Code to load tools and data
 # packages
    library(ape)
    require(arm)
    library(brms)
    library(car)
    library(coda)
    require(data.table)
    library(dplyr)
    require(effects)
    require(foreach)
    library(geiger)
    require(ggimage)
    require(ggplot2)
    require(ggpubr)
    require(ggsci)
    require(ggtext)
    require(grid)
    require(gtable)
    require(here)
    require(kableExtra)
    library(magrittr)
    require(MASS)
    library(MCMCglmm)
    require(multcomp)
    require(optimx)
    library(parallel)
    require(patchwork)
    require(performance)  
    require(PerformanceAnalytics)
    library(phangorn)
    library(phylobase)
    library(phytools)
    library(plyr)
    require(png)
    require(RColorBrewer)
    require(rmeta)
    require(rphylopic)
    require(scales)
    library(stringr)
    require(viridis)

 # constants
    save_plot = TRUE
    round_ = 3 # number of decimal places to round model coefficients
    nsim = 5000 # number of simulations to extract estimates and 95%CrI
    ax_lines = "grey60" # defines color of the axis lines
    #colors <- c("#999999", "#E69F00", "#56B4E9") #viridis(3)
    set.seed(42)
    #width_ = .7 # spacing between error bars
    #col_ = c(brewer.pal(n =12, name = "Paired"), 'grey30','grey80')
 # functions
    # mode
      Mode <- function(x) {
        ux <- unique(x)
        ux[which.max(tabulate(match(x, ux)))]
      }
    # to add images to panels
      annotation_custom2 <- function (grob, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf, data) {
        layer(data = data, stat = StatIdentity, position = PositionIdentity, 
            geom = ggplot2:::GeomCustomAnn,
            inherit.aes = TRUE, params = list(grob = grob, 
                                              xmin = xmin, xmax = xmax, 
                                              ymin = ymin, ymax = ymax))
      }
    # to remove ggplot components
        gtable_filter_remove <- function (x, name, trim = TRUE){
          matches <- !(x$layout$name %in% name)
          x$layout <- x$layout[matches, , drop = FALSE]
          x$grobs <- x$grobs[matches]
          if (trim) 
            x <- gtable_trim(x)
          x
        }
    # customized ggplot theme
        theme_MB = theme(  
                  title = element_text(size=8, colour="grey30"),
                  axis.line = element_blank(),
                  #axis.line = element_line(colour="grey70", size=0.25),
                  axis.title = element_text(size=7, colour="grey30"),
                  axis.title.y = element_text(vjust=3.5),
                  axis.title.x = element_text(vjust=1),
                  axis.text = element_text(size=6),#, vjust = 0.5, hjust=1),# margin=units(0.5,"mm")),
                  axis.ticks.length=unit(0.5,"mm"),
                  axis.ticks = element_line(colour = "grey70", size = 0.1),
                  #axis.ticks.margin,
                  
                  strip.text.x = element_text(size = 6, color="grey30",  margin=margin(1,1,1,1,"mm")), #grey50
                  strip.text.y = element_text(size = 6, color="grey30",  margin=margin(1,1,1,1,"mm")), #grey50
                  strip.background = element_rect(fill="grey99",colour="grey70", size=0.25),
                    #strip.background = element_blank(), 
                    #strip.text = element_blank(),
                  panel.spacing = unit(0, "mm"),
                  panel.background=element_blank(),
                  panel.border = element_rect(colour="grey70", size=0.1, fill = NA), #panel.border=element_blank(),
                  panel.grid = element_blank(),

                  legend.text=element_text(size=6),
                  legend.title=element_text(size=6),
                  legend.key = element_rect(colour = NA, fill = NA),
                  legend.key.height= unit(0.5,"line"),
                  legend.key.width = unit(0.25, "cm"),
                  legend.margin = margin(0,0,0,0, unit="cm"),
                  legend.box.margin = margin(l = -6), #legend.justification = c(-1,0),
                  legend.background = element_blank()
                  )  
    # for estimates
        est_out =function(model = m, label = "", nsim = 5000){
            bsim = sim(model, n.sim=5000) 
            v = apply(bsim@fixef, 2, quantile, prob=c(0.5))
            ci = apply(bsim@fixef, 2, quantile, prob=c(0.025,0.975)) 
            sd = apply(bsim@fixef, 2, sd)
            data.table(predictor=rownames(coef(summary(model))),estimate=v, lwr=ci[1,], upr=ci[2,], sd = sd, model = paste(label, "N =", nobs(model)))
          }
    # change color
      change_col = function(replace_black, theimg) {
        r_b = col2rgb(replace_black) / 255
        #theimg[theimg == 1] <- 2
        for (i in 1:3) {
            theimg[,,i][theimg[,,i] == 0] <- r_b[i]
        }
        return(theimg)
        }
    # for Supplementary Table output based on sim
      m_out = function(model = m, type = "mixed", 
        name = "define", dep = "define", fam = 'Gaussian',
        round_ = 3, nsim = 5000, aic = FALSE, save_sim = here::here('Data/model_sim/'), back_tran = FALSE, perc_ = 1){
          # perc_ 1 = proportion or 100%
        bsim = sim(model, n.sim=nsim)  
        
        if(save_sim!=FALSE){save(bsim, file = paste0(save_sim, name,'.RData'))}
       
        if(type != "mixed"){
          v = apply(bsim@coef, 2, quantile, prob=c(0.5))
          ci = apply(bsim@coef, 2, quantile, prob=c(0.025,0.975)) 

          if(back_tran == TRUE & fam == "binomial"){
           v = perc_*plogis(v)
           ci = perc_*plogis(ci)
           }
          if(back_tran == TRUE & fam == "binomial_logExp"){
                v = perc_*(1-plogis(v))
                ci = perc_*(1-plogis(ci))
                ci = rbind(ci[2,],ci[1,])
               }

          if(back_tran == TRUE & fam == "Poisson"){
           v = exp(v)
           ci = exp(ci)
          }

         oi=data.frame(type='fixed',effect=rownames(coef(summary(model))),estimate=v, lwr=ci[1,], upr=ci[2,])
          rownames(oi) = NULL
          oi$estimate_r=round(oi$estimate,round_)
          oi$lwr_r=round(oi$lwr,round_)
          oi$upr_r=round(oi$upr,round_)
          if(perc_ == 100){
           oi$estimate_r = paste0(oi$estimate_r,"%")
           oi$lwr_r = paste0(oi$lwr_r,"%")
           oi$upr_r = paste0(oi$upr_r,"%")
          }
         x=data.table(oi[c('type',"effect", "estimate_r","lwr_r",'upr_r')]) 
       
        }else{
         v = apply(bsim@fixef, 2, quantile, prob=c(0.5))
         ci = apply(bsim@fixef, 2, quantile, prob=c(0.025,0.975)) 

         if(back_tran == TRUE & fam == "binomial"){
          v = perc_*plogis(v)
          ci = perc_*plogis(ci)
         }
          if(back_tran == TRUE & fam == "binomial_logExp"){
                v = perc_*(1-plogis(v))
                ci = perc_*(1-plogis(ci))
                ci = rbind(ci[2,],ci[1,])
               }

          if(back_tran == TRUE & fam == "Poisson"){
            v = exp(v)
            ci = exp(ci)
         }

        oi=data.table(type='fixed',effect=rownames(coef(summary(model))),estimate=v, lwr=ci[1,], upr=ci[2,])
            rownames(oi) = NULL
            oi[,estimate_r := round(estimate,round_)]
            oi[,lwr_r := round(lwr,round_)]
            oi[,upr_r :=round(upr,round_)]
            if(perc_ == 100){
             oi[,estimate_r := paste0(estimate_r,"%")]
             oi[,lwr_r := paste0(lwr_r,"%")]
             oi[,upr_r := paste0(upr_r,"%")]
            }
         oii=oi[,c('type',"effect", "estimate_r","lwr_r",'upr_r')] 
        
         l=data.frame(summary(model)$varcor)
         l = l[is.na(l$var2),]
         l$var1 = ifelse(is.na(l$var1),"",l$var1)
         l$pred = paste(l$grp,l$var1)

         q050={}
         q025={}
         q975={}
         pred={}
         
         # variance of random effects
         for (ran in names(bsim@ranef)) {
           ran_type = l$var1[l$grp == ran]
           for(i in ran_type){
            q050=c(q050,quantile(apply(bsim@ranef[[ran]][,,ran_type], 1, var), prob=c(0.5)))
            q025=c(q025,quantile(apply(bsim@ranef[[ran]][,,ran_type], 1, var), prob=c(0.025)))
            q975=c(q975,quantile(apply(bsim@ranef[[ran]][,,ran_type], 1, var), prob=c(0.975)))
            pred= c(pred,paste(ran, i))
            }
           }
         # residual variance
         q050=c(q050,quantile(bsim@sigma^2, prob=c(0.5)))
         q025=c(q025,quantile(bsim@sigma^2, prob=c(0.025)))
         q975=c(q975,quantile(bsim@sigma^2, prob=c(0.975)))
         pred= c(pred,'Residual')

         ri=data.table(type='random',effect=pred, estimate_r=round(100*q050/sum(q050)), lwr_r=round(100*q025/sum(q025)), upr_r=round(100*q975/sum(q975)))
           
         ri[lwr_r>upr_r, lwr_rt := upr_r]
         ri[lwr_r>upr_r, upr_rt := lwr_r]
         ri[!is.na(lwr_rt), lwr_r := lwr_rt]
         ri[!is.na(upr_rt), upr_r := upr_rt]
         ri$lwr_rt = ri$upr_rt = NULL

         ri[,estimate_r := paste0(estimate_r,'%')]
         ri[,lwr_r := paste0(lwr_r,'%')]
         ri[,upr_r := paste0(upr_r,'%')]
        
        x = data.table(rbind(oii,ri))
        }
        
        x[1, model := name]                                                                
        x[1, response := dep]                                                                
        x[1, error_structure := fam]      
        N = length(resid(model))                                                          
        x[1, N := N ]                                                                

        x=x[ , c('model', 'response', 'error_structure', 'N', 'type',"effect", "estimate_r","lwr_r",'upr_r')] 

        if (aic == TRUE){   
            x[1, AIC := AIC(update(model,REML = FALSE))] 
            }
        if (aic == "AICc"){
            aicc = AICc(model)
            x[1, AICc := aicc] 
        }
        if(type == "mixed" & nrow(x[type=='random' & estimate_r =='0%'])==0){
          R2_mar = as.numeric(r2_nakagawa(model)$R2_marginal)
          R2_con = as.numeric(r2_nakagawa(model)$R2_conditional)
          x[1, R2_mar := R2_mar]
          x[1, R2_con := R2_con]
         }
        x[is.na(x)] = ""
        return(x)
      } 
    # model assumption function
      m_ass = function(name = 'define', mo = m0, dat = d, fixed = NULL, categ = NULL, trans = "none", spatial = TRUE, temporal = TRUE, PNG = TRUE, outdir = 'outdir', n_col=8, width_ = 10, height_ = 5.5){
       l=data.frame(summary(mo)$varcor)
       l = l[is.na(l$var2),]
       nt = if(temporal==TRUE){1}else{0}
       ns = if(spatial==TRUE){7}else{0}
       n = 3+nrow(l)-1+length(fixed)+length(categ) +  nt +  ns
     
       if(PNG == TRUE){
        png(paste(outdir,name, ".png", sep=""), width=width_,height=height_,units="in",res=150) # width = 6
        par(mfrow=c(4, n_col),tcl = -0.08, cex = 0.5, cex.main = 0.9,#ceiling(n/n_col),n_col)
            oma = c(1,1,4,1),
            mar = c(2, 2, 2, 1), mgp=c(1,0,0)
            )
         }else{
          dev.new(width=width_,height=height_)
          par(mfrow=c(4,n_col), tcl = -0.08, cex = 0.5, cex.main = 0.9,#ceiling(n/n_col),n_col)
            oma = c(1,1,2,1),
            mar = c(2, 2, 2, 1), mgp=c(1,0,0)
            )
        }
       
       scatter.smooth(fitted(mo),resid(mo),col='grey');abline(h=0, lty=2, col ='red')
       scatter.smooth(fitted(mo),sqrt(abs(resid(mo))), col='grey')
       qqnorm(resid(mo), main=list("Normal Q-Q Plot: residuals"),col='grey');qqline(resid(mo), col = 'red')
       #unique(l$grp[l$grp!="Residual"])
       for(i in unique(l$grp[l$grp!="Residual"])){
        #i = "mean_year"
        ll=ranef(mo)[names(ranef(mo))==i][[1]]
        if(ncol(ll)==1){
         qqnorm(ll[,1], main = paste(i,names(ll)[1]),col='grey',);qqline(ll[,1], col ='red')
         }else{
          qqnorm(ll[,1], main = paste(i,names(ll)[1]),col='grey');qqline(ll[,1], col ='red')
          qqnorm(ll[,2], main = paste(i,names(ll)[2]),col='grey');qqline(ll[,2], col ='red')
         }
        }
        
       # variables
         scatter={} 
         for (i in rownames(summary(mo)$coef)) {
              # i = "lat_abs" #i = rownames(summary(mo)$coef)[9]
            j=sub("\\).*", "", sub(".*\\(", "",i)) 
            scatter[length(scatter)+1]=j
          }
          x = data.frame(scatter=unique(scatter)[2:length(unique(scatter))],
                          log_ = grepl("log",rownames(summary(mo)$coef)[2:length(unique(scatter))]), stringsAsFactors = FALSE)
          for (i in 1:length(fixed)){
              jj =fixed[i] # jj = fixed[1]
              #print(jj)
              variable=dat[, ..jj][[1]]
              if(trans[i]=='log'){
              scatter.smooth(resid(mo)~log(variable),xlab=paste('log(',jj,')',sep=''), col = 'grey');abline(h=0, lwd=1, lty = 2, col ='red')
              }else if(trans[i]=='abs'){
              scatter.smooth(resid(mo)~abs(variable),xlab=paste('abs(',jj,')',sep=''), col = 'grey');abline(h=0, lwd=1, lty = 2, col ='red')
              }else if(trans[i]=='sin'){scatter.smooth(resid(mo)~sin(variable),xlab=paste('sin(',jj,')',sep=''), col = 'grey');abline(h=0, lwd=1, lty = 2, col ='red')
              }else if(trans[i]=='cos'){scatter.smooth(resid(mo)~cos(variable),xlab=paste('cos(',jj,')',sep=''), col = 'grey');abline(h=0, lwd=1, lty = 2, col ='red')
              }else{
              scatter.smooth(resid(mo)~variable,xlab=jj,col = 'grey');abline(h=0, lwd=1, lty = 2, col ='red')
            }
           }
          
          if(length(categ)>0){
            for(i in categ){
               variable=dat[, ..i][[1]]
                boxplot(resid(mo)~variable, medcol='grey', whiskcol='grey', staplecol='grey', boxcol='grey', outcol='grey', xlab = i);abline(h=0, lty=3, lwd=1, col = 'red')
               }
          }     
              
        if(temporal == TRUE){
            acf(resid(mo), type="p", main=list("Temporal autocorrelation:\npartial series residual"))
            }
        if(spatial == TRUE){    
          spdata=data.frame(resid=resid(mo), x=dat$Lon, y=dat$Lat)
            spdata$col=ifelse(spdata$resid<0,rgb(83,95,124,100, maxColorValue = 255),ifelse(spdata$resid>0,rgb(253,184,19,100, maxColorValue = 255), 'red'))
            #cex_=c(1,2,3,3.5,4)
            cex_=c(1,1.5,2,2.5,3)
            spdata$cex=as.character(cut(abs(spdata$resid), 5, labels=cex_))
          plot(spdata$x, spdata$y,col=spdata$col, cex=as.numeric(spdata$cex), pch= 16, main=list('Spatial distribution of residuals', cex=0.8), xlab = 'Longitude', ylab = 'Latitude')
            legend("topright", pch=16, legend=c('>0','<0'), ,col=c(rgb(83,95,124,100, maxColorValue = 255),rgb(253,184,19,100, maxColorValue = 255)))
          plot(spdata$x[spdata$resid<0], spdata$y[spdata$resid<0],col=spdata$col[spdata$resid<0], cex=as.numeric(spdata$cex[spdata$resid<0]), pch= 16, main=list('residuals <0'), xlab = 'Longitude', ylab = 'Latitude')
          plot(spdata$x[spdata$resid>=0], spdata$y[spdata$resid>=0],col=spdata$col[spdata$resid>=0], cex=as.numeric(spdata$cex[spdata$resid>=0]), pch= 16, main=list('residual >=0'), xlab = 'Longitude', ylab = 'Latitude')
          
          if('Australia'%in%unique(dat$Country) & length(unique(dat$Country))>1){
          # EU
          dat$res = resid(mo)
          spdata=data.frame(resid = dat$res[dat$Country!='Australia'], x=dat$Lon[dat$Country!='Australia'], y=dat$Lat[dat$Country!='Australia'])
          spdata$col=ifelse(spdata$resid<0,rgb(83,95,124,100, maxColorValue = 255),ifelse(spdata$resid>0,rgb(253,184,19,100, maxColorValue = 255), 'red'))
            #cex_=c(1,2,3,3.5,4)
            cex_=c(1,1.5,2,2.5,3)
            spdata$cex=as.character(cut(abs(spdata$resid), 5, labels=cex_))
          plot(spdata$x[spdata$resid<0], spdata$y[spdata$resid<0],col=spdata$col[spdata$resid<0], cex=as.numeric(spdata$cex[spdata$resid<0]), pch= 16, main=list('EU -  residuals <0'), xlab = 'Longitude', ylab = 'Latitude')
          plot(spdata$x[spdata$resid>=0], spdata$y[spdata$resid>=0],col=spdata$col[spdata$resid>=0], cex=as.numeric(spdata$cex[spdata$resid>=0]), pch= 16, main=list('EU residuals >=0)'), xlab = 'Longitude', ylab = 'Latitude')

          # Australia
          spdata=data.frame(resid = dat$res[dat$Country=='Australia'], x=dat$Lon[dat$Country=='Australia'], y=dat$Lat[dat$Country=='Australia'])
          spdata$col=ifelse(spdata$resid<0,rgb(83,95,124,100, maxColorValue = 255),ifelse(spdata$resid>0,rgb(253,184,19,100, maxColorValue = 255), 'red'))
            #cex_=c(1,2,3,3.5,4)
            cex_=c(1,1.5,2,2.5,3)
            spdata$cex=as.character(cut(abs(spdata$resid), 5, labels=cex_))
          plot(spdata$x[spdata$resid<0], spdata$y[spdata$resid<0],col=spdata$col[spdata$resid<0], cex=as.numeric(spdata$cex[spdata$resid<0]), pch= 16, main=list('Australia residuals <0'), xlab = 'Longitude', ylab = 'Latitude')
          plot(spdata$x[spdata$resid>=0], spdata$y[spdata$resid>=0],col=spdata$col[spdata$resid>=0], cex=as.numeric(spdata$cex[spdata$resid>=0]), pch= 16, main=list('Australia residuals >=0'), xlab = 'Longitude', ylab = 'Latitude')
          }
        }
  
       mtext(stringr::str_wrap(paste(paste0(name," model: "), slot(mo,"call")[1],'(',slot(mo,"call")[2],sep=''), width = ceiling(nchar(paste(slot(mo,"call")[1],'(',slot(mo,"call")[2],sep=''))/2)+10), side = 3, line = 1, cex=0.5,outer = TRUE, col = 'darkblue') #ceiling(nchar(paste(slot(mo,"call")[1],'(',slot(mo,"call")[2],sep=''))/2)
       if(PNG==TRUE){dev.off()}
      }
    
 # data
    t = fread(here::here("Data/taxonomy.txt"))
    
    ph  =  fread(here::here('Data/phylopic.txt'))
    setnames(ph, old = c('Name', 'Code'), new = c('genus2', 'uid'))

    g = fread(here::here('Data/google_mobility.txt')) #fwrite(d, here::here('Data/data.txt'), sep ='\t')
    g[, Year := as.integer(substring(date, nchar(date)-3, nchar(date)))]
    g[nchar(date)==9, date:=paste0('0',date)]
    g[, date_ :=as.Date(date, format = '%d.%m.%Y')]
    g[, Day :=yday(date_)]
    setnames(g, old = "country_region", new = "Country")

    # adjust correct assignment of breeding season (Year) for Australiato the the year of when a given breeding season started
    g[Country != "Australia", Day := Day - 92 + 1] # 1 April = start of breeding season (1st day) = 92 day of the year
    g[Country == "Australia", Day := Day - 228 + 1] # 15 Augusst = start of breeding season (1st day) = 228 day of the year
    
    d = fread(here::here('Data/data.txt')) #fwrite(d, here::here('Data/data.txt'), sep ='\t')
    d[Human == 0, humans := 0]
    d[Human > 0, humans := 1] # dh = dh[!(Country%in%'Czechia' & Year == 2018)]
  
    # adjust correct assignment of breeding season (Year) for Australiato the the year of when a given breeding season started
    d[Country == 'Australia' & Year == 2020 & Covid == 0, Year:=2019]
    d[Country == 'Australia' & Year == 2021 & Day>139, Year:=2020]
    d[Country == 'Australia' & Year == 2022 & Day>139, Year:=2021]

    d = d[order(Year, IDLocality, Day, Hour)]
    d[, year_ := as.character(Year)]
    d[Country %in% c("Czech_Republic", "Czech Republic"), Country := "Czechia"]
    d[, genus := sub("_.*", "", Species)]
    d[, sp_day_year := paste(Year, Species, Day, sep="_")]
    d[, sp_loc := paste(Species, IDLocality, sep="_")]
    d[, sp_country := paste(Species, Country, sep="\n")]
    d[, rad:=(2*pi*Hour) / 24]
    d[, Day_:= Day]
    #d[, FID_z := scale(FID), by = Species]
    #d[, SD_z := scale(SD), by = Species]
    d[, FID_ln := log(FID)]
    d[, SD_ln := log(SD)]
    d[, body_ln := log(BodyMass)]
    d[, flock_ln := log(FlockSize)]
    d[, weekday := weekdays(date_)]
    #d[Country == 'Australia', Day_:= abs(Day - 189)]

    # species with data before and during
    d1 = d[Covid == 1, .N, by = Species]
    d2 = d[Covid == 0, .N, by = Species]
    setnames(d1, old = 'N', new ='N_during')
    setnames(d2, old = 'N', new ='N_before')
    dd = merge(d1, d2) # species with data before and during
    da = merge(d1,d2, all = TRUE)

    # species with data before and during
    d1p = d[Country!='Poland' & Covid == 1, .N, by = Species]
    d2p = d[Country!='Poland' & Covid == 0, .N, by = Species]
    setnames(d1p, old = 'N', new ='N_during')
    setnames(d2p, old = 'N', new ='N_before')
    ddp = merge(d1p,d2p) # species with data before and during, but without Poland data

    # species-localities with data before and during
    p1 = d[Covid == 1, .N, by = .(IDLocality, Species)]
    p2 = d[Covid == 0, .N, by = .(IDLocality, Species)]
    setnames(p1, old = 'N', new ='N_during')
    setnames(p2, old = 'N', new ='N_before')
    pp = merge(p1,p2)  # species-localities with data before and during
    pa = merge(p1,p2, all = TRUE)

    # species-localities with data before and during,but without Poland data
    p1p = d[Country!='Poland' & Covid == 1, .N, by = .(IDLocality, Species)]
    p2p = d[Country!='Poland' & Covid == 0, .N, by = .(IDLocality, Species)]
    setnames(p1p, old = 'N', new ='N_during')
    setnames(p2p, old = 'N', new ='N_before')
    ppp = merge(p1p,p2p)  # species-localities with data before and during,but without Poland data 

    # species-localities with data before and during, but without Poland & 2014 data
    p1p4 = d[Year!=2014 & Country!='Poland' & Covid == 1, .N, by = .(IDLocality, Species)]
    p2p4 = d[Year!=2014 & Country!='Poland' & Covid == 0, .N, by = .(IDLocality, Species)]
    setnames(p1p4, old = 'N', new ='N_during')
    setnames(p2p4, old = 'N', new ='N_before')
    ppp4 = merge(p1p4,p2p4) # species-localities with data before and during, but without Poland & 2014 data

    # add google mobility
    d[, sp := gsub("[_]", " ", Species)]
    d = merge(d, g[,.(Country,  date_, parks_percent_change_from_baseline)], all.x = TRUE, by = c('Country', 'date_'))
     
    # limit to data with # of humans
    dh = d[!is.na(Human)] # summary(factor(dh$Year))
    dh[, Nsp := .N, by = "Species"]
    dh[, Country := factor(Country, levels = (c("Finland", "Poland", "Czechia", "Hungary")))]
    dh[Covid == 0, Period := "Before COVID-19 shutdown"]
    dh[Covid == 1, Period := "During COVID-19 shutdown"]

    # limit to data with # of humans > 0
    dhh <- dh[Human > 0]
    dhh[, Country := factor(Country, levels = (c("Finland", "Poland", "Czechia", "Hungary")))]
    dhh[Covid == 0, Period := "Before COVID-19 shutdown"]
    dhh[Covid == 1, Period := "During COVID-19 shutdown"]
    
    # limit to COVID-19 period (Stringeny data)
    s = d[Covid == 1]
    s[, Nsp := .N, by = "Species"]
    s[, year_weekday := paste(Year, weekday)]

    # limit to data with Google Mobility
    ss = s[!is.na(parks_percent_change_from_baseline)]
    ss[, country_year := paste(Country, Year)] #table(paste(s$Country, s$Year))   
    ss[parks_percent_change_from_baseline<0, google := 'before_zero']
    ss[parks_percent_change_from_baseline>0, google := 'after_zero']
    ss[, sp_country_google:= paste(sp_country, google)]

    g[, weekday := weekdays(date_)]

    # limit stringency data to those with # of humans
    sh <- s[!is.na(Human)]
    sh[, year_day := paste(Year, Day)]
    sh[, year_weekday := paste(Year, weekday)]

    # limit Google data # limit to data with # of humans
    ssh <- ss[!is.na(Human)]
    ssh[, year_day := paste(Year, Day)]
    ssh[, year_weekday := paste(Year, weekday)]

    # add sinam
    d[, scinam := Species]
    s[, scinam := Species]
    ss[, scinam := Species]
    dh[, scinam := Species]

Introduction

To facilitate transparency, the following document contains example code used to generate the results of the manuscript. Thus, apart from the supplementary figures and tables, below we display also main text figures. The figures and tables are ordered according to their appearance in the main text. The code is displayed upon clicking the “code” icon at the top right, above each display item. Continuous variables were standardised by subtracting the mean and dividing by the standard deviation. For descriptions of variables see Methods of the paper. ‘Residual’ in tables indicates residual variance.

When using this content PLEASE CITE the paper and this repository (Martin Bulla, Peter Mikula, Daniel T. Blumstein, Yanina Benedetti, Kristina Floigl, Jukka Jokimäki, Marja-Liisa Kaisanlahti-Jokimäki, Gábor Markó, Federico Morelli, Anders Pape Møller, Anastasiia Siretckaia, Sára Szakony, Michael A. Weston, Farah Abou Zeid, Piotr Tryjanowski & Tomáš Albrecht (2023), *Supporting information for ‘Urban birds’ flight responses were largely unaffected by the COVID-19 shutdowns’, GitHub, https://martinbulla.github.io/avian_FID_covid/).

Questions can be directed to &


Repository: files & folders

Supplementary information, including code: the current html document with supplementary informatiion, figures and tables.

R-scripts used in the analysis:
- _runRmarkdown.R generates htmls from the following R-script:
- REV_ms_output.R used to generate the Supplement, contains all scripts used to generate the paper outputs, including the display items

Data: raw data (for their description see READ_ME and manipulated data (starting with ‘DAT_’) generated with R-scripts and used in the further analyses
- model_sim: posterior simulations for given models
- Pics: phylopic pictures used in the graphs

Outputs: separate files of all outputs used in the manuscript and this Supplement

LICENSE: terms of reuse - applicable only after this work is published as a preprint or in a scientific journal, until then the data are not available for reuse.


Effect sizes for Period

# predictions
# full
ms <- lmer(scale(log(FID)) ~
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
    (1 | Year) + (1 | weekday) + (1| genus) + (1| Species) + (1 | sp_day_year) + (scale(Covid) | Country) + (scale(Covid) | IDLocality) + (1 | sp_loc),
data = d, REML = FALSE,
control <- lmerControl(
    optimizer = "optimx", optCtrl = list(method = "nlminb")
)
)
est_ms <- est_out(ms, "All: (1|Year) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (1|sp_loc)")
est_ms[, control_for_starting_distance := "yes"]

mx <- lmer(scale(log(FID)) ~
    #scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
    (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Covid) | Country) + (scale(Covid) | IDLocality) + (1 | sp_loc),
    data = d, REML = FALSE,
        control = lmerControl( 
            optimizer ='optimx', optCtrl=list(method='nlminb')) 
        )  
# (Covid|IDLocality) +
est_mx <- est_out(mx, "All: (1|Year) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (1|sp_loc)")
est_mx[, control_for_starting_distance := "no"]

# CZ - singular fits only due to genera estimated as zero (removing it changes no results)
  cs <- lmer(scale(log(FID)) ~
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
    (1 | Year) + (1 | weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (scale(Covid)| IDLocality) + (1|sp_loc),
    #(1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
    data = d[Country == "Czechia"], REML = FALSE
    )
  est_cs <- est_out(cs, "Czechia: (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)+(scale(Covid)|IDLocality)+(1|sp_loc)")
  est_cs[, control_for_starting_distance := "yes"]
  
  cx <- lmer(scale(log(FID)) ~
    #scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
    (1 | Year) + (1 | weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (scale(Covid)| IDLocality) + (1|sp_loc),
    #(1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
    data = d[Country == "Czechia"], REML = FALSE
    )
  est_cx <- est_out(cx, "Czechia: (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)+(scale(Covid)|IDLocality)+(1|sp_loc)")
  est_cx[, control_for_starting_distance := "no"]

# FI
fs <- lmer(scale(log(FID)) ~
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
    (1 | Year) + (1 | weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (scale(Covid)| IDLocality) + (1|sp_loc),
data = d[Country == "Finland"], REML = FALSE
)
est_fs <- est_out(fs, "Finland: (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)+(scale(Covid)|IDLocality)+(1|sp_loc)")
est_fs[, control_for_starting_distance := "yes"]

fx <- lmer(scale(log(FID)) ~
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
     (1 | Year) + (1 | weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (scale(Covid)| IDLocality) + (1|sp_loc),
data = d[Country == "Finland"], REML = FALSE
)
est_fx <- est_out(fx, "Finland: (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)+(scale(Covid)|IDLocality)+(1|sp_loc)")
est_fx[, control_for_starting_distance := "no"]

# HU - singular fits only due to sp_loc estimated as zero (removing it changes no results)
hs <- lmer(scale(log(FID)) ~
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
    (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Covid) | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = d[Country == "Hungary"], REML = FALSE
)
est_hs <- est_out(hs, "Hungary: (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)+(scale(Covid)|IDLocality)+(1|sp_loc)")
est_hs[, control_for_starting_distance := "yes"]

hx <- lmer(scale(log(FID)) ~
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
    (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Covid) | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = d[Country == "Hungary"], REML = FALSE
)
est_hx <- est_out(hx, "Hungary: (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)+(scale(Covid)|IDLocality)+(1|sp_loc)")
est_hx[, control_for_starting_distance := "no"]

# AU - singular fits only due to Year and random slope estimated as zero (removing those changes no results)
as <- lmer(scale(log(FID)) ~
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
     (1 | Year) +(1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Covid) | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = d[Country == "Australia"], REML = FALSE
)
est_as <- est_out(as, "Australia: (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)+(scale(Covid)|IDLocality)+(1|sp_loc)")
est_as[, control_for_starting_distance := "yes"]

ax <- lmer(scale(log(FID)) ~
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
    (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Covid) | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = d[Country == "Australia"], , REML = FALSE,
        control = lmerControl( 
            optimizer ='optimx', optCtrl=list(method='nlminb')) 
)
est_ax <- est_out(ax, "Australia: (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)+(scale(Covid)|IDLocality)+(1|sp_loc)")
est_ax[, control_for_starting_distance := "no"]

# PL 
ps <- lmer(scale(log(FID)) ~
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
    (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = d[Country == "Poland"], REML = FALSE
)
est_ps <- est_out(ps, "Poland: (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)")
est_ps[, control_for_starting_distance := "yes"]

px <- lmer(scale(log(FID)) ~
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(Covid) +
    (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = d[Country == "Poland"], REML = FALSE
)
est_px <- est_out(px, "Poland: (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)")
est_px[, control_for_starting_distance := "no"]

  # combine
    est_ms[, Country := 'All\n(mixed model)']
    est_mx[, Country := "All\n(mixed model)"]
    est_as[, Country := "Australia"]
    est_ax[, Country := "Australia"]
    est_cs[, Country := "Czechia"]
    est_cx[, Country := "Czechia"]
    est_hs[, Country := "Hungary"]
    est_hx[, Country := "Hungary"]
    est_ps[, Country := "Poland"]
    est_px[, Country := "Poland"]
    est_fs[, Country := "Finland"]
    est_fx[, Country := "Finland"]

    o = rbind(est_ms, est_mx, 
            est_as, est_ax, 
            est_cs, est_cx, 
            est_hs, est_hx,
            est_ps, est_px, 
            est_fs, est_fx)
    save(o, file = here::here('Data/dat_est_rev.Rdata'))
 
  #AIC(hs, hx)
  #AIC(cs, cx)
  #0AIC(ps, px)
  #AIC(as, ax)
  #AIC(fs, fx)

# supplementary Sable S_fid_period  
  ms_out <- m_out(name = "Table S1 - full a", dep = "Escape distance", model = ms, nsim = 5000)
  mx_out <- m_out(name = "Table S1 - full b", dep = "Escape distance", model = mx, nsim = 5000)
  cs_out <- m_out(name = "Table S1 - CZ a", dep = "Escape distancey", model = cs, nsim = 5000)
  cx_out <- m_out(name = "Table S1 - CZ b", dep = "Escape distance", model = cx, nsim = 5000)
  fs_out <- m_out(name = "Table S1 - FI a", dep = "Escape distance", model = fs, nsim = 5000)
  fx_out <- m_out(name = "Table S1 - FI b", dep = "Escape distance", model = fx, nsim = 5000)
  hs_out <- m_out(name = "Table S1 - HU a", dep = "Escape distance", model = hs, nsim = 5000)
  hx_out <- m_out(name = "Table S1 - HU b", dep = "Escape distance", model = hx, nsim = 5000)
  as_out <- m_out(name = "Table S1 - AU a", dep = "Escape distance", model = as, nsim = 5000)
  ax_out <- m_out(name = "Table S1 - AU b", dep = "Escape distance", model = ax, nsim = 5000)
  ps_out <- m_out(name = "Table S1 - PL a", dep = "Escape distance", model = ps, nsim = 5000)
  px_out <- m_out(name = "Table S1 - PL b", dep = "Escape distance", model = px, nsim = 5000)
  
  out_FID_c <- rbind(fs_out, fx_out, ps_out, px_out, cs_out, cx_out, hs_out, hx_out, as_out, ax_out, fill = TRUE)
  out_FID_c[is.na(out_FID_c)] <- ""
  out_FID_c$R2_mar = out_FID_c$R2_con = NULL
  out_FID_c[, effect := gsub("scale\\(Covid\\)", "Period", effect)]
  out_FID_c[, effect := gsub("scale\\(Year\\)", "year", effect)]
  out_FID_c[, effect := gsub("scale\\(log\\(SD\\)\\)", "starting distance (ln)", effect)]
  out_FID_c[, effect := gsub("scale\\(Temp\\)", "temperature", effect)]
  out_FID_c[, effect := gsub("scale\\(log\\(FlockSize\\)\\)", "flock size (ln)", effect)]
  out_FID_c[, effect := gsub("scale\\(log\\(BodyMass\\)\\)", "body mass (ln)", effect)]
  out_FID_c[, effect := gsub("scale\\(sin\\(rad\\)\\)", "time (sine of radians)", effect)]
  out_FID_c[, effect := gsub("scale\\(cos\\(rad\\)\\)", "time (cosine of radians)", effect)]
  out_FID_c[, effect := gsub("Species", "species", effect)]
  out_FID_c[, effect := gsub("Year", "year", effect)]
  out_FID_c[, effect := gsub("sp_day_year", "species within day & year", effect)]
  out_FID_c[, effect := gsub("IDLocality", "site", effect)]
  out_FID_c[, effect := gsub("sp_loc", "species within site", effect)]
  out_FID_c[, effect := gsub("site Period", "Period (slope) | site", effect)]
  fwrite(file = here::here("Outputs/Table_S1.csv"), out_FID_c)
load(here::here("Data/dat_est_rev.Rdata"))
o[predictor %in% c("scale(Covid)"), predictor := "Period"]
oo <- o[predictor %in% c("Period")]
oo[, N:=as.numeric(sub('.*N = ', '', model))]
# add meta-analytical mean
  oo_s = oo[control_for_starting_distance == 'yes']
  met = summary(meta.summaries(d = oo_s$estimate, se = oo_s$sd, method = "fixed", weights = oo_s$N))$summci
  oo_met = data.table(predictor = "Period", estimate = met[2], lwr = met[1], upr = met[3], sd = NA, model = NA, control_for_starting_distance = "yes", Country = "Combined\n(metanalytical)", N = NA)

  oo_sx = oo[control_for_starting_distance == "no"]
  metx = summary(meta.summaries(d = oo_sx$estimate, se = oo_sx$sd, method = "fixed", weights = oo_sx$N))$summci
  oo_metx = data.table(predictor = "Period", estimate = metx[2], lwr = metx[1], upr = metx[3], sd = NA, model = NA, control_for_starting_distance = "no", Country = "Combined\n(metanalytical)", N = NA)
  
  oo = rbind(oo, oo_met, oo_metx)
    
oo[, Country := factor(Country, levels = rev(c("Finland", "Poland", "Czechia", "Hungary", "Australia", "Combined\n(metanalytical)", "All\n(mixed model)")))]

# prepare for adding N
oo[control_for_starting_distance == "no" | is.na(N), N := ""]
oo[, n_pos := 1.1]

width_ <- .5 # spacing between error bars

#col_ <- c(brewer.pal(n = 12, name = "Paired"), "grey30", "grey80")
#Tol_bright <- c("#EE6677", "#228833", "#4477AA", "#CCBB44", "#66CCEE", "#AA3377", "#BBBBBB")
#Tol_muted <- c("#88CCEE", "#44AA99", "#117733", "#332288", "#DDCC77", "#999933", "#CC6677", "#882255", "#AA4499", "#DDDDDD")
#Tol_light <- c("#BBCC33", "#AAAA00", "#77AADD", "#EE8866", "#EEDD88", "#FFAABB", "#99DDFF", "#44BB99", "#DDDDDD")

# From Color Universal Design (CUD): https://jfly.uni-koeln.de/color/
#Okabe_Ito <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", "#000000")
#col_ = Okabe_Ito[7:1]
# JAMA and LocusZoom modified order
#col_ =  c("#374E55FF", "#374E55FF", "#DF8F44FF", "#79AF97FF", "#00A1D5FF", "#B24745FF",  "#80796BFF") #"#6A6599FF",
#col_ <- c("#357EBDFF", "#9632B8FF", "#46B8DAFF", "#5CB85CFF", "#EEA236FF", "#D43F3AFF", "#D43F3AFF")[7:1] # "#D43F3AFF", "#B8B8B8FF"
col_ = c("#357EBDFF", "#D43F3AFF", "#46B8DAFF", "#5CB85CFF", "#EEA236FF", "#9632B8FF", "#9632B8FF")[7:1] # "#D43F3AFF", "#B8B8B8FF"
#show_col(col_)

g_f1 = 
ggplot(oo, aes(x = estimate, y = Country, col = Country, shape = control_for_starting_distance)) +
    geom_vline(xintercept = 0, color = "grey", linetype = "dotted") +
    geom_errorbarh(aes(xmin = lwr, xmax = upr), height = 0, position = ggstance::position_dodgev(width_)) +
    # geom_point(position = ggstance::position_dodgev(.6)) +
    geom_point(position = position_dodge(width = width_), bg = "white", size = 1.1) +
    # scale_color_viridis(discrete=TRUE, begin=0, end = 0.5)  +
    # scale_fill_viridis(discrete=TRUE, begin=0, end = 0.5) +
    # geom_text( aes(x = n_pos,label = N), vjust = 0, size = 1.75, position = ggstance::position_dodgev(width_))+ # 3 positions for 3 bars
    # annotate("text", x=log10(3), y=85, label= "Used", col = "grey30", size = 2.5)+
    geom_text( aes(x = n_pos,label = N), vjust = 1, size = 1.75, position = ggstance::position_dodgev(width_))+
    scale_shape_manual(name = "Controlled for\nstarting distance", guide = guide_legend(reverse = TRUE), values = c(21, 19)) +
    #scale_color_jama(guide = "none")+ #, palette = 'light'
    scale_color_manual(guide = "none", values = col_) + #guide_legend(reverse = TRUE)
    scale_x_continuous(breaks = round(seq(-0.6, 1.2, by = 0.3), 1)) +
    ylab("") +
    xlab("Standardised effect size of Period\n[on flight initiation distance]") +
    # coord_cartesian(xlim = c(-.15, .15)) +
    # scale_x_continuous(breaks = round(seq(-.15, .15, by = 0.05),2)) +
    theme_bw() +
    theme(
        legend.position = "right",
        legend.title = element_text(size = 7),
        legend.text = element_text(size = 6),
        # legend.spacing.y = unit(0.1, 'cm'),
        legend.key.height = unit(0.5, "line"),
        legend.margin = margin(0, 0, 0, 0),
        # legend.position=c(0.5,1.6),
        plot.title = element_text(color = "grey", size = 7),
        plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r = 0.5, unit = "pt"),
        panel.grid = element_blank(),
        panel.border = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = ax_lines, size = 0.25),
        axis.line.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.ticks.x = element_line(colour = ax_lines, size = 0.25),
        # axis.text.x = element_text()
        axis.ticks.length = unit(1, "pt"),
        axis.text.x = element_text(, size = 6),
        axis.text.y = element_text(colour = "black", size = 7),
        axis.title = element_text(size = 7)
    )
if(save_plot==TRUE){
ggsave(here::here("Outputs/Fig_1_width-80mm.png"), g_f1,  width = 8, height = 6.5, unit = "cm", dpi = 600)
}
#ggsave("Outputs/Fig_rev_width_CustomJAMAv1.png", width = 8, height = 6, unit = "cm", dpi = 600)
#ggsave("Outputs/Fig_rev_width_Okabe_v2.png", width = 8, height = 6, unit = "cm", dpi = 600)
#ggsave("Outputs/Fig_rev_width_UChicago_v3.png", width = 8, height = 6, unit = "cm", dpi = 600)
#ggsave("Outputs/Fig_rev_width_d3_v2.png", width = 8, height = 6, unit = "cm", dpi = 600)
#ggsave("Outputs/Fig_rev_width_nejm_v2.png", width = 8, height = 6, unit = "cm", dpi = 600)
#ggsave("Outputs/Fig_rev_width_jama_v2.png", width = 8, height = 6, unit = "cm", dpi = 600)
#ggsave("Outputs/Fig_rev_width_jco_v2.png", width = 8, height = 6, unit = "cm", dpi = 600)
#ggsave("Outputs/Fig_rev_width_npg_v2.png", width = 8, height = 6, unit = "cm", dpi = 600)
# show used colors
# gg <- ggplot_build(p)
# col_ = unique(gg$data[[3]]["colour"])$colour
# show_col(col_)

g_f1

Figure 1 | Change in avian tolerance towards humans before vs during the COVID-19 shutdowns. The dots with horizontal lines represent estimated standardised effect size and their 95% confidence intervals, the numbers sample sizes. For the country-specific and "All“, the effect sizes and 95% confidence intervals come from the joint posterior distribution of 5000 simulated values generated by the sim function from the arm package (Gelman et al., 2022) using the mixed model outputs controlled for starting distance of the observer (filled circles) or not (empty circles; Tables S1 and S2a). The models were further controlled for flock size, body size, temperature (also a proxy for a day within the breeding season: rPearson = 0.48; Fig. S2), and time of a day, as well as for the non-independence of data points by fitting random intercepts of year, weekday, genus, species, species at a given day and year, country (in All - a global mixed model), site, and species within a site, while fitting Period as random slope within site (i.e. allowing for different Period effect at each site) and in All also within country. Fitting Period as random slope at other random intercepts produces similar results (see Fig. S1a). The multicollinearity was small as correlations between predictors were weak (Fig. S2). For the “Combined“, the estimate and 95% confidence interval represent the meta-analytical mean based on the country estimates and their standard deviation (from the country-specific models), and sample size per country. Note that effect sizes are small and estimates centre around zero.

Table S1 | Escape distance in relations to Period, given country

out_FID_c$error_structure = out_FID_c$response = NULL
out_FID_c[model!="", model:=c('Finland', 'Finland, without starting distance', 
                              'Poland', 'Poland, without starting distance',
                              'Czechia', 'Czechia, without starting distance',
                              'Hungary', 'Hungary, without starting distance',
                              'Australia', 'Australia, without starting distance')]
setnames(out_FID_c, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
out_FID_c %>%
  kbl() %>%
  kable_paper("hover", full_width = F)
model N type effect estimate lower upper
Finland 1019 fixed (Intercept) -0.035 -0.321 0.231
fixed starting distance (ln) 0.282 0.228 0.336
fixed flock size (ln) -0.049 -0.101 0.001
fixed body mass (ln) 0.091 -0.066 0.24
fixed time (sine of radians) 0.085 0.022 0.147
fixed time (cosine of radians) 0.031 -0.028 0.088
fixed temperature -0.079 -0.148 -0.009
fixed Period -0.15 -0.337 0.031
random species within day & year (Intercept) 10% 9% 11%
random species within site (Intercept) 6% 5% 7%
random site (Intercept) 1% 0% 3%
random Period (slope) | site 1% 0% 3%
random species (Intercept) 4% 3% 5%
random genus (Intercept) 10% 7% 14%
random weekday (Intercept) 0% 0% 1%
random year (Intercept) 5% 1% 11%
random Residual 61% 50% 72%
Finland, without starting distance 1019 fixed (Intercept) -0.125 -0.468 0.221
fixed flock size (ln) -0.018 -0.07 0.034
fixed body mass (ln) 0.2 0.03 0.375
fixed time (sine of radians) 0.093 0.026 0.161
fixed time (cosine of radians) 0.029 -0.032 0.089
fixed temperature -0.076 -0.148 -0.005
fixed Period -0.132 -0.366 0.101
random species within day & year (Intercept) 9% 7% 10%
random species within site (Intercept) 7% 6% 7%
random site (Intercept) 1% 1% 2%
random Period (slope) | site 1% 1% 2%
random species (Intercept) 7% 5% 8%
random genus (Intercept) 10% 7% 13%
random weekday (Intercept) 1% 0% 1%
random year (Intercept) 9% 2% 16%
random Residual 56% 44% 68%
Poland 762 fixed (Intercept) 0.145 -0.115 0.404
fixed starting distance (ln) 0.479 0.419 0.538
fixed flock size (ln) 0.012 -0.042 0.066
fixed body mass (ln) -0.07 -0.172 0.031
fixed time (sine of radians) -0.035 -0.117 0.05
fixed time (cosine of radians) -0.012 -0.101 0.078
fixed temperature -0.111 -0.182 -0.04
fixed Period 0.119 -0.112 0.353
random species within day & year (Intercept) 8% 8% 8%
random species (Intercept) 15% 12% 17%
random genus (Intercept) 0% 0% 0%
random weekday (Intercept) 0% 0% 1%
random year (Intercept) 11% 7% 17%
random Residual 66% 57% 72%
Poland, without starting distance 762 fixed (Intercept) 0.246 -0.075 0.558
fixed flock size (ln) 0.054 -0.009 0.117
fixed body mass (ln) 0.046 -0.097 0.19
fixed time (sine of radians) -0.014 -0.112 0.077
fixed time (cosine of radians) -0.001 -0.104 0.099
fixed temperature -0.104 -0.187 -0.02
fixed Period 0.245 0.001 0.498
random species within day & year (Intercept) 11% 10% 11%
random species (Intercept) 26% 22% 29%
random genus (Intercept) 1% 1% 2%
random weekday (Intercept) 0% 0% 0%
random year (Intercept) 8% 5% 14%
random Residual 53% 46% 60%
Czechia 2013 fixed (Intercept) 0.111 -0.257 0.481
fixed starting distance (ln) 0.392 0.351 0.437
fixed flock size (ln) 0.005 -0.03 0.037
fixed body mass (ln) 0.17 0.038 0.308
fixed time (sine of radians) 0.05 0.002 0.099
fixed time (cosine of radians) 0.054 0.009 0.097
fixed temperature 0.043 -0.008 0.093
fixed Period 0.036 -0.294 0.361
random species within day & year (Intercept) 3% 2% 3%
random species within site (Intercept) 3% 2% 3%
random species (Intercept) 13% 12% 13%
random site (Intercept) 2% 0% 3%
random Period (slope) | site 2% 0% 3%
random genus (Intercept) 12% 11% 11%
random weekday (Intercept) 0% 0% 0%
random year (Intercept) 15% 1% 33%
random Residual 52% 34% 70%
Czechia, without starting distance 2013 fixed (Intercept) -0.043 -0.969 0.867
fixed flock size (ln) 0.005 -0.031 0.04
fixed body mass (ln) 0.231 0.078 0.382
fixed time (sine of radians) 0.14 0.086 0.195
fixed time (cosine of radians) 0.123 0.075 0.172
fixed temperature 0.035 -0.027 0.098
fixed Period 0.223 -0.642 1.1
random species within day & year (Intercept) 2% 1% 5%
random species within site (Intercept) 1% 1% 2%
random species (Intercept) 6% 4% 10%
random site (Intercept) 1% -1% 1%
random Period (slope) | site 1% -1% 1%
random genus (Intercept) 8% 5% 11%
random weekday (Intercept) 1% 0% 1%
random year (Intercept) 54% 17% 73%
random Residual 26% 13% 57%
Hungary 1456 fixed (Intercept) 0.097 -0.174 0.384
fixed starting distance (ln) 0.485 0.438 0.531
fixed flock size (ln) -0.012 -0.051 0.031
fixed body mass (ln) -0.065 -0.184 0.059
fixed time (sine of radians) -0.077 -0.133 -0.019
fixed time (cosine of radians) -0.011 -0.06 0.037
fixed temperature -0.023 -0.083 0.037
fixed Period -0.091 -0.271 0.097
random species within day & year (Intercept) 5% 4% 5%
random species within site (Intercept) 0% 0% 0%
random species (Intercept) 3% 2% 3%
random genus (Intercept) 7% 5% 8%
random site (Intercept) 2% 0% 8%
random Period (slope) | site 2% 0% 8%
random weekday (Intercept) 1% 0% 1%
random year (Intercept) 5% 2% 8%
random Residual 76% 59% 84%
Hungary, without starting distance 1456 fixed (Intercept) 0.078 -0.336 0.494
fixed flock size (ln) -0.011 -0.057 0.035
fixed body mass (ln) 0.187 0.006 0.376
fixed time (sine of radians) -0.111 -0.18 -0.044
fixed time (cosine of radians) -0.007 -0.06 0.05
fixed temperature -0.025 -0.095 0.043
fixed Period -0.105 -0.307 0.109
random species within day & year (Intercept) 7% 5% 8%
random species within site (Intercept) 0% 0% 0%
random species (Intercept) 2% 2% 2%
random genus (Intercept) 18% 13% 18%
random site (Intercept) 1% 0% 12%
random Period (slope) | site 1% 0% 12%
random weekday (Intercept) 1% 0% 1%
random year (Intercept) 5% 3% 7%
random Residual 63% 42% 74%
Australia 1119 fixed (Intercept) -0.064 -0.202 0.081
fixed starting distance (ln) 0.502 0.452 0.553
fixed flock size (ln) 0.02 -0.026 0.068
fixed body mass (ln) -0.066 -0.163 0.029
fixed time (sine of radians) -0.032 -0.099 0.036
fixed time (cosine of radians) -0.026 -0.093 0.041
fixed temperature 0.009 -0.045 0.063
fixed Period -0.009 -0.08 0.062
random species within day & year (Intercept) 7% 6% 7%
random species within site (Intercept) 13% 11% 13%
random species (Intercept) 14% 11% 13%
random genus (Intercept) 2% 1% 2%
random site (Intercept) 0% -1% 8%
random Period (slope) | site 0% -1% 8%
random weekday (Intercept) 0% 0% 0%
random year (Intercept) 0% 0% 0%
random Residual 64% 51% 68%
Australia, without starting distance 1119 fixed (Intercept) -0.18 -0.432 0.058
fixed flock size (ln) 0.051 -0.002 0.104
fixed body mass (ln) 0.055 -0.073 0.184
fixed time (sine of radians) -0.017 -0.098 0.063
fixed time (cosine of radians) -0.006 -0.08 0.069
fixed temperature 0.004 -0.058 0.067
fixed Period 0.156 -0.007 0.331
random species within day & year (Intercept) 8% 5% 10%
random species within site (Intercept) 12% 8% 15%
random species (Intercept) 17% 14% 17%
random genus (Intercept) 5% 4% 5%
random site (Intercept) 1% -10% 15%
random Period (slope) | site 1% -10% 15%
random weekday (Intercept) 0% 0% 0%
random year (Intercept) 1% 0% 2%
random Residual 55% 36% 73%

For model descriptions see legend of Fig. 1, for descriptions of variables Methods of the paper.


Alternative models give similar results

  # width = 30, height = 20, units = "cm"
  # prepare estimates Period
    # 01a all data, main text
      m1a <- lmer(scale(log(FID)) ~
        scale(log(SD)) +
        scale(log(FlockSize)) +
        scale(log(BodyMass)) +
        scale(sin(rad)) + scale(cos(rad)) +
        # scale(Day)+
        scale(Temp) +
        scale(Covid) +
        (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Covid) | Country) + (scale(Covid) | IDLocality) + (1 | sp_loc),
      data = d, REML = FALSE,
       control = lmerControl(
         optimizer = "optimx", optCtrl = list(method = "nlminb")
       )
      )
     est_m1a = est_out(m1a, "01a) (1|Year) + (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (1|sp_loc)")
    # 01b all data, all random slopes - singularity 
      m1b=lmer(scale(log(FID))~
                  scale(log(SD))+
                  scale(log(FlockSize))+
                  scale(log(BodyMass))+
                  scale(sin(rad)) + scale(cos(rad)) + 
                  #scale(Day)+
                  scale(Temp)+
                  scale(Covid)+
                  (1|Year) + (1 | weekday) + (scale(Covid)|genus)+(scale(Covid)|Species)+(1|sp_day_year) + (scale(Covid)|Country) +(scale(Covid)|IDLocality) + (scale(Covid)|sp_loc),
                  data = d, REML = FALSE
                )
                  # # (Covid|IDLocality) +
      est_m1b = est_out(m1b, "01b) (1|Year) + (1|weekday) + (scale(Covid)|genus) + (scale(Covid)|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (scale(Covid)|sp_loc)")
    # 01c all data, all random slopes, but some without cor to avoid singularity
      m1c=lmer(scale(log(FID))~
                  scale(log(SD))+
                  scale(log(FlockSize))+
                  scale(log(BodyMass))+
                  scale(sin(rad)) + scale(cos(rad)) + 
                  #scale(Day)+
                  scale(Temp)+
                  scale(Covid)+
                  #(1|Year) +(0+Covid|genus)+(0+Covid|Species)+(1|sp_day_year) + (Covid|Country) + (0+Covid|IDLocality) +(Covid|sp_loc)
                  (1|Year)+ (1|weekday) + (0+scale(Covid)|genus)+(0+scale(Covid)|Species)+(1|sp_day_year) + (scale(Covid)|Country) +(scale(Covid)|IDLocality) + (scale(Covid)|sp_loc),
                  data = d, REML = FALSE) # (0+scale(Covid)|genus) is zero 
      est_m1c = est_out(m1c, "01c) (1|Year) + (1|weekday) + (0+scale(Covid)|genus) + (0+scale(Covid)|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (scale(Covid)|sp_loc)")
    # 01d all data, random slopes that allow for non-singular fit 
      m1d=lmer(scale(log(FID))~
                  scale(log(SD))+
                  scale(log(FlockSize))+
                  scale(log(BodyMass))+
                  scale(sin(rad)) + scale(cos(rad)) + 
                  #scale(Day)+
                  scale(Temp)+
                  scale(Covid)+
                  (1|Year) + (1|weekday) +(1|genus)+(1|Species)+(1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (scale(Covid)|sp_loc),
                  data = d, REML = FALSE)# (Covid|IDLocality) +
      #d[,res := resid(mf)]
      est_m1d = est_out(m1d, "01d) (1|Year) + (1|weekday)+ (1|genus) + (1|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (scale(Covid)|sp_loc)")
    # 01e all data, random slopes that allow for non-singular fit with simple structure
      m1e=lmer(scale(log(FID))~
                  scale(log(SD))+
                  scale(log(FlockSize))+
                  scale(log(BodyMass))+
                  scale(sin(rad)) + scale(cos(rad)) + 
                  #scale(Day)+
                  scale(Temp)+
                  scale(Covid)+
                  (1|Year) + (1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year) + (scale(Covid)|Country) + (1|IDLocality) + (1|sp_loc),
                  data = d, REML = FALSE)# (Covid|IDLocality) +
      est_m1e = est_out(m1e, "01e) (1|Year) + (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (1|IDLocality) + (1|sp_loc)")

    # 02a) before & during > 4/species - main text 
      dx = dd[N_during>4 & N_before >4]
      #dxx = d[Species %in% dx$Species]
      #dx2 = dd[N_during>9 & N_before >9]
      m2a <- lmer(scale(log(FID)) ~
        scale(log(SD)) +
        scale(log(FlockSize)) +
        scale(log(BodyMass)) +
        scale(sin(rad)) + scale(cos(rad)) +
        # scale(Day)+
        scale(Temp) +
        scale(Covid) +
        (1 | Year) + (1| weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Covid) | Country) + (scale(Covid) | IDLocality) + (1 | sp_loc),
      data = d[Species %in% dx$Species], REML = FALSE,
       control = lmerControl(
         optimizer = "optimx", optCtrl = list(method = "nlminb")
       )
      )
      est_m2a = est_out(m2a, "02a) (1|Year) + (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (1|sp_loc); >4/species/period")
    
    # 02b) before & during > 4/species - singularity
      dx = dd[N_during > 4 & N_before > 4]
      m2b=lmer(scale(log(FID))~
                  scale(log(SD))+
                  scale(log(FlockSize))+
                  scale(log(BodyMass))+
                  scale(sin(rad)) + scale(cos(rad)) + 
                  #scale(Day)+
                  scale(Temp)+
                  scale(Covid)+
                  (1|Year) + (1| weekday)+ (scale(Covid)|genus)+(scale(Covid)|Species)+(1|sp_day_year) + (scale(Covid)|Country) +(scale(Covid)|IDLocality) + (scale(Covid)|sp_loc),
                  #(1|Year) + (1|genus)+(1|Species)+(1|sp_day_year) + (Covid|Country) + (Covid|sp_loc),
                  data = d[Species %in% dx$Species],
                  REML = FALSE) # (Covid|IDLocality) +
      est_m2b = est_out(m2b, "02b) (1|Year) + (1|weekday)+ (scale(Covid)|genus)+(scale(Covid)|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (scale(Covid)|sp_loc); >4/species/period")
    # 02c) before & during > 4/species, random slopes that allow for non-singular fit and simple structure
      dx = dd[N_during>4 & N_before >4]
      #dxx = d[Species %in% dx$Species]
      #dx2 = dd[N_during>9 & N_before >9]
      m2c=lmer(scale(log(FID))~
                  scale(log(SD))+
                  scale(log(FlockSize))+
                  scale(log(BodyMass))+
                  scale(sin(rad)) + scale(cos(rad)) + 
                  #scale(Day)+
                  scale(Temp)+
                  scale(Covid)+
                  (1|Year)+ (1| weekday) +(1|genus)+(1|Species)+(1|sp_day_year) + (scale(Covid)|Country) + (1|IDLocality) + (1|sp_loc),
                  #(1|Year) + (1|genus)+(1|Species)+(1|sp_day_year) + (Covid|Country) + (Covid|sp_loc),
                  data = d[Species %in% dx$Species],
                  REML = FALSE) # (Covid|IDLocality) +
      est_m2c = est_out(m2c, "02c) (1|Year) + (1|weekday)+ (1|genus) + (1|Species)+(1|sp_day_year) + (scale(Covid)|Country) + (1|IDLocality) + (1|sp_loc); >4/species/period")
    # 03a) before & during > 9/species - main text
      dx = dd[N_during > 9 & N_before > 9]
      m3a <- lmer(scale(log(FID)) ~
       scale(log(SD)) +
       scale(log(FlockSize)) +
       scale(log(BodyMass)) +
       scale(sin(rad)) + scale(cos(rad)) +
       # scale(Day)+
       scale(Temp) +
       scale(Covid) +
       (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Covid) | Country) + (scale(Covid) | IDLocality) + (1 | sp_loc),
      data = d[Species %in% dx$Species], REML = FALSE,
      )
     est_m3a = est_out(m3a, "03a) (1|Year) + (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (1|sp_loc); >9/species/period")
    # 03b) before & during > 9/species - singularity 
      dx = dd[N_during>9 & N_before >9]
      #dxx = d[Species %in% dx$Species]
      #dx2 = dd[N_during>9 & N_before >9]
      m3b=lmer(scale(log(FID))~
                  scale(log(SD))+
                  scale(log(FlockSize))+
                  scale(log(BodyMass))+
                  scale(sin(rad)) + scale(cos(rad)) + 
                  #scale(Day)+
                  scale(Temp)+
                  scale(Covid)+
                  (1|Year) + (1| weekday) + (scale(Covid)|genus)+(scale(Covid)|Species)+(1|sp_day_year) + (scale(Covid)|Country) +(scale(Covid)|IDLocality) + (scale(Covid)|sp_loc),
                  #(1|Year) + (1|genus)+(1|Species)+(1|sp_day_year) + (Covid|Country) + (Covid|sp_loc),
                  data = d[Species %in% dx$Species],
                  REML = FALSE) # (Covid|IDLocality) +
      est_m3b = est_out(m3b, "03b) (1|Year) + (1|weekday) + (scale(Covid)|genus)+(scale(Covid)|Species) + (1|sp_day_year) + (scale(Covid)|Country) + (scale(Covid)|IDLocality) + (scale(Covid)|sp_loc); >9/species/period")
    # 03c) before & during > 9/species, random slopes that allow for non-singular fit and simple structure
      dx = dd[N_during>9 & N_before >9]
      #dxx = d[Species %in% dx$Species]
      #dx2 = dd[N_during>9 & N_before >9]
      m3c=lmer(scale(log(FID))~
                  scale(log(SD))+
                  scale(log(FlockSize))+
                  scale(log(BodyMass))+
                  scale(sin(rad)) + scale(cos(rad)) + 
                  #scale(Day)+
                  scale(Temp)+
                  scale(Covid)+
                  (1|Year) + (1| weekday) +(1|genus)+(1|Species)+(1|sp_day_year) + (scale(Covid)|Country) + (1|IDLocality) + (1|sp_loc),
                  #(1|Year) + (1|genus)+(1|Species)+(1|sp_day_year) + (Covid|Country) + (Covid|sp_loc),
                  data = d[Species %in% dx$Species],
                  REML = FALSE) # (Covid|IDLocality) +
      est_m3c = est_out(m3c, '03c) (1|Year) + (1|genus) + (1|Species)+(1|sp_day_year) + (scale(Covid)|Country) + (1|IDLocality) + (1|sp_loc); >9/species/period')  
  
  # prepare estimates Stringency 
    m01a <- lmer(scale(log(FID)) ~
      scale(Year) +
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(StringencyIndex) +
      (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(StringencyIndex) | Country) + (1 | IDLocality) + (1 | sp_loc),
      data = s, REML = FALSE)
    est_m01a = est_out(m01a, "01a) (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(StringencyIndex)|Country) + (1|IDLocality) +(1|sp_loc)")

    m01b=lmer(scale(log(FID))~ 
        scale(Year)+ 
        scale(log(SD))+ 
        scale(log(FlockSize))+ 
        scale(log(BodyMass))+ 
        scale(sin(rad)) + scale(cos(rad)) +  
        #scale(Day)+ 
        scale(Temp)+ 
        scale(StringencyIndex)+ 
        (1|weekday) + (scale(StringencyIndex)|genus)+(1|Species)+(1|sp_day_year) + (scale(StringencyIndex)|Country) + (1|IDLocality) +(1|sp_loc),
        data = s, REML = FALSE
        )  
        # (1|Year) explains nothing - could stay 
     est_m01b = est_out(m01b, "01b) (1|weekday) + (scale(StringencyIndex)|genus) + (1|Species) + (1|sp_day_year) + (scale(StringencyIndex)|Country) + (1|IDLocality) +(1|sp_loc)")
     
     m01c=lmer(scale(log(FID))~
          scale(Year)+       
          scale(log(SD))+
          scale(log(FlockSize))+
          scale(log(BodyMass))+
          scale(sin(rad)) + scale(cos(rad)) + 
          #scale(Day)+
          scale(Temp)+
          scale(StringencyIndex)+
          (scale(StringencyIndex)|Country) + (1|IDLocality),  
          data = s, REML = FALSE) 
          # (1|Year), (1|genus), (1|sp_day_year), (1|sp_loc),  explain nothing - could stay
     est_m01c = est_out(m01c, "01c) (scale(StringencyIndex)|Country) + (1|IDLocality)")

     m02a <- lmer(scale(log(FID)) ~
       scale(Year) +
       scale(log(SD)) +
       scale(log(FlockSize)) +
       scale(log(BodyMass)) +
       scale(sin(rad)) + scale(cos(rad)) +
       # scale(Day)+
       scale(Temp) +
       scale(StringencyIndex) +
       (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(StringencyIndex) | Country) + (1 | IDLocality) + (1 | sp_loc),
     data = s[Nsp>4], REML = FALSE
     )

     est_m02a = est_out(m02a, "02a) (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(StringencyIndex)|Country) + (1|IDLocality) +(1|sp_loc); >4/species")
    m02b=lmer(scale(log(FID))~ 
        scale(Year)+ 
        scale(log(SD))+ 
        scale(log(FlockSize))+ 
        scale(log(BodyMass))+ 
        scale(sin(rad)) + scale(cos(rad)) +  
        #scale(Day)+ 
        scale(Temp)+ 
        scale(StringencyIndex)+ 
        (1|weekday) + (scale(StringencyIndex)|genus)+(1|Species)+(1|sp_day_year) + (scale(StringencyIndex)|Country) + (1|IDLocality) +(1|sp_loc),
        data = s[Nsp>4], REML = FALSE,  
        control = lmerControl( 
            optimizer ='optimx', optCtrl=list(method='nlminb')) 
        )  
        # (1|Year) explains nothing - could stay 
     est_m02b = est_out(m02b, "02b) (1|weekday) + (scale(StringencyIndex)|genus) + (1|Species) + (1|sp_day_year) + (scale(StringencyIndex)|Country) + (1|IDLocality) +(1|sp_loc); >4/species")
     
     m02c=lmer(scale(log(FID))~
          scale(Year)+       
          scale(log(SD))+
          scale(log(FlockSize))+
          scale(log(BodyMass))+
          scale(sin(rad)) + scale(cos(rad)) + 
          #scale(Day)+
          scale(Temp)+
          scale(StringencyIndex)+
          (scale(StringencyIndex)|Country) + (1|IDLocality),  
          data = s[Nsp>4], REML = FALSE) 
          # (1|Year), (1|genus), (1|sp_day_year), (1|sp_loc),  explain nothing - could stay
      est_m02c = est_out(m02c, "02c) (scale(StringencyIndex)|Country) + (1|IDLocality); >4/species")

      m03a <- lmer(scale(log(FID)) ~
           scale(Year) +
           scale(log(SD)) +
           scale(log(FlockSize)) +
           scale(log(BodyMass)) +
           scale(sin(rad)) + scale(cos(rad)) +
           # scale(Day)+
           scale(Temp) +
           scale(StringencyIndex) +
           (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(StringencyIndex) | Country) + (1 | IDLocality) + (1 | sp_loc),
         data = s[Nsp > 9], REML = FALSE
         )

         est_m03a = est_out(m03a, "03a) (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(StringencyIndex)|Country) + (1|IDLocality) +(1|sp_loc); >9/species")
         m03b = lmer(scale(log(FID)) ~
           scale(Year) +
           scale(log(SD)) +
           scale(log(FlockSize)) +
           scale(log(BodyMass)) +
           scale(sin(rad)) + scale(cos(rad)) +
           # scale(Day)+
           scale(Temp) +
           scale(StringencyIndex) +
           (1 | weekday) + (scale(StringencyIndex) | genus) + (1 | Species) + (1 | sp_day_year) + (scale(StringencyIndex) | Country) + (1 | IDLocality) + (1 | sp_loc),
         data = s[Nsp > 9], REML = FALSE
         )
         est_m03b = est_out(m03b, "03b) (1|weekday) + (scale(StringencyIndex)|genus) + (1|Species) + (1|sp_day_year) + (scale(StringencyIndex)|Country) + (1|IDLocality) +(1|sp_loc); >9/species")

        m03c = lmer(scale(log(FID)) ~
           scale(Year) +
           scale(log(SD)) +
           scale(log(FlockSize)) +
           scale(log(BodyMass)) +
           scale(sin(rad)) + scale(cos(rad)) +
           # scale(Day)+
           scale(Temp) +
           scale(StringencyIndex) +
           (scale(StringencyIndex) | Country) + (1 | IDLocality),
         data = s[Nsp > 9], REML = FALSE
         )
         # (1|Year), (1|genus), (1|sp_day_year), (1|sp_loc),  explain nothing - could stay
         est_m03c = est_out(m03c, "03c) (scale(StringencyIndex)|Country) + 1|IDLocality); >9/species")

  # prepare estimates google mobility 
    mg01a=lmer(scale(log(FID))~
      scale(Year)+       
      scale(log(SD))+
      scale(log(FlockSize))+
      scale(log(BodyMass))+
      scale(sin(rad)) + scale(cos(rad)) + 
      #scale(Day)+
      scale(Temp)+
      scale(parks_percent_change_from_baseline)+
      (1|weekday) + (1|genus) +(1|Species) + (1|sp_day_year) + (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality)+(1|sp_loc),  
      data = ss, REML = FALSE
      ) 
      # (1|Year), (1|genus), (1|sp_day_year), (1|sp_loc),  explain nothing - could stay
    est_mg01a = est_out(mg01a, "01a) (1|weekday) + (1|genus) +(1|Species) + (1|sp_day_year) + (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality)+(1|sp_loc)")
    
    mg01b <- lmer(scale(log(FID)) ~
     scale(Year) +
     scale(log(SD)) +
     scale(log(FlockSize)) +
     scale(log(BodyMass)) +
     scale(sin(rad)) + scale(cos(rad)) +
     # scale(Day)+
     scale(Temp) +
     scale(parks_percent_change_from_baseline) +
     (1|weekday) + (scale(parks_percent_change_from_baseline)| genus) + (1 | Species) + (1 | sp_day_year) + 
     (scale(parks_percent_change_from_baseline)| Country) + (1 | IDLocality) + (1 | sp_loc),
     data = ss, REML = FALSE
     ) 

     est_mg01b = est_out(mg01b, "01b) (1|weeekday) + (scale(parks_percent_change_from_baseline)|genus)+(1|Species)+(1|sp_day_year) + (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality) +(1|sp_loc)")
     
    mg01c <- lmer(scale(log(FID)) ~
      scale(Year) +
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(parks_percent_change_from_baseline) +
      (scale(parks_percent_change_from_baseline) | Country) + (1 | IDLocality),
    data = ss, REML = FALSE
    )
    est_mg01c = est_out(mg01c, "01c) (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality)")

    mg02a = lmer(scale(log(FID)) ~
      scale(Year) +
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(parks_percent_change_from_baseline) +
      (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(parks_percent_change_from_baseline) | Country) + (1 | IDLocality) + (1 | sp_loc),
    data = ss[Nsp>4], REML = FALSE
    )
    # (1|Year), (1|genus), (1|sp_day_year), (1|sp_loc),  explain nothing - could stay
    est_mg02a = est_out(mg02a, "02a) (1|weekday) + (1|genus) +(1|Species) + (1|sp_day_year) + (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality)+(1|sp_loc); >4/specie")

    mg02b <- lmer(scale(log(FID)) ~
      scale(Year) +
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(parks_percent_change_from_baseline) +
      (1 | weekday) + (scale(parks_percent_change_from_baseline) | genus) + (1 | Species) + (1 | sp_day_year) +
      (scale(parks_percent_change_from_baseline) | Country) + (1 | IDLocality) + (1 | sp_loc),
    data = ss[Nsp>4], REML = FALSE
    )

    est_mg02b = est_out(mg02b, "02b) (1|weeekday) + (scale(parks_percent_change_from_baseline)|genus)+(1|Species)+(1|sp_day_year) + (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality) +(1|sp_loc); >4/specie")

    mg02c <- lmer(scale(log(FID)) ~
      scale(Year) +
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(parks_percent_change_from_baseline) +
      (scale(parks_percent_change_from_baseline) | Country) + (1 | IDLocality),
    data = ss[Nsp>4], REML = FALSE
    )
    est_mg02c = est_out(mg02c, "02c) (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality); >4/specie")

    mg03a = lmer(scale(log(FID)) ~
      scale(Year) +
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(parks_percent_change_from_baseline) +
      (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(parks_percent_change_from_baseline) | Country) + (1 | IDLocality) + (1 | sp_loc),
    data = ss[Nsp > 9], REML = FALSE
    )
    # (1|Year), (1|genus), (1|sp_day_year), (1|sp_loc),  explain nothing - could stay
    est_mg03a = est_out(mg03a, "03a) (1|weekday) + (1|genus) +(1|Species) + (1|sp_day_year) + (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality)+(1|sp_loc); >9/specie")

    mg03b <- lmer(scale(log(FID)) ~
      scale(Year) +
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(parks_percent_change_from_baseline) +
      (1 | weekday) + (scale(parks_percent_change_from_baseline) | genus) + (1 | Species) + (1 | sp_day_year) +
      (scale(parks_percent_change_from_baseline) | Country) + (1 | IDLocality) + (1 | sp_loc),
    data = ss[Nsp > 9], REML = FALSE
    )

    est_mg03b = est_out(mg03b, "03b) (1|weeekday) + (scale(parks_percent_change_from_baseline)|genus)+(1|Species)+(1|sp_day_year) + (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality) +(1|sp_loc); >9/specie")

    mg03c <- lmer(scale(log(FID)) ~
      scale(Year) +
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(parks_percent_change_from_baseline) +
      (scale(parks_percent_change_from_baseline) | Country) + (1 | IDLocality),
    data = ss[Nsp > 9], REML = FALSE
    )
    est_mg03c = est_out(mg03c, "03c) (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality); >9/specie")

  # prepare estimates number of humans
    mh01a=lmer(scale(log(FID))~  
      scale(log(SD))+
      scale(log(FlockSize))+
      scale(log(BodyMass))+
      scale(sin(rad)) + scale(cos(rad)) + 
      #scale(Day)+
      scale(Temp)+
      scale(Human)+
      (1 | Year) + (1|weekday) + (1|genus) +(1|Species) + (1|sp_day_year) + (scale(Human)|Country) + (1|IDLocality)+(1|sp_loc),  
      data = dh, REML = FALSE
      ) 
    est_mh01a = est_out(mh01a, "01a) (1|Year) + (1|weekday) + (1|genus) +(1|Species) + (1|sp_day_year) + (scale(Human)|Country) + (1|IDLocality)+(1|sp_loc)")
    
    mh01b <- lmer(scale(log(FID)) ~
     scale(log(SD)) +
     scale(log(FlockSize)) +
     scale(log(BodyMass)) +
     scale(sin(rad)) + scale(cos(rad)) +
     # scale(Day)+
     scale(Temp) +
     scale(Human) +
     (1|Year) + (1|weekday) + (0+scale(Human)| genus) + (1 | Species) + (0+scale(Human) | sp_day_year) + 
     (scale(Human)| Country) + (1 | IDLocality) + (1 | sp_loc),
     data = dh, REML = FALSE
     ) 
     est_mh01b = est_out(mh01b, "01b) (1|Year) + (1|weeekday) + (0 + scale(Human)|genus)+(1|Species)+(0 + scale(Human)|sp_day_year) + (scale(Human)|Country) + (1|IDLocality) +(1|sp_loc)")
     
    mh01c <- lmer(scale(log(FID)) ~
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(Human) +
      (1|Year) + (1|genus) + (1|sp_day_year) + (scale(Human) | Country) + (1 | IDLocality) +(1|sp_loc),
    data = dh, REML = FALSE
    )
    est_mh01c = est_out(mh01c, "01c) (1|Year) + (1|genus) + (1|sp_day_year) + (scale(Human)|Country) + (1|IDLocality) +(1|sp_loc)")

    mh02a = lmer(scale(log(FID)) ~
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(Human) +
      (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Human) | Country) + (1 | IDLocality) + (1 | sp_loc),
    data = dh[Nsp>4], REML = FALSE
    )
    est_mh02a = est_out(mh02a, "02a) (1|Year) + (1|weekday) + (1|genus) +(1|Species) + (1|sp_day_year) + (scale(Human)|Country) + (1|IDLocality)+(1|sp_loc); >4/specie")

    mh02b <- lmer(scale(log(FID)) ~
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(Human) +
      (1 | Year) + (1 | weekday) + (scale(Human) | genus) + (1 | Species) + (1 | sp_day_year) +
      (scale(Human) | Country) + (1 | IDLocality) + (1 | sp_loc),
    data = dh[Nsp>4], REML = FALSE
    )

    est_mh02b = est_out(mh02b, "02b) (1|Year) + (1|weeekday) + (scale(Human)|genus)+(1|Species)+(1|sp_day_year) + (scale(Human)|Country) + (1|IDLocality) +(1|sp_loc); >4/specie")

    mh02c <- lmer(scale(log(FID)) ~
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(Human) +
      (1|Year) + (1|genus) + (1|sp_day_year) + (scale(Human) | Country) + (1 | IDLocality) +(1|sp_loc),
    data = dh[Nsp>4], REML = FALSE
    )

    est_mh02c = est_out(mh02c, "02c) (1|Year) + (1|genus) + (1|sp_day_year) + (scale(Human)|Country) + (1|IDLocality) +(1|sp_loc); >4/specie")

    mh03a = lmer(scale(log(FID)) ~
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(Human) +
      (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Human) | Country) + (1 | IDLocality) + (1 | sp_loc),
    data = dh[Nsp > 9], REML = FALSE
    )
    est_mh03a = est_out(mh03a, "03a) (1|Year) + (1|weekday) + (1|genus) +(1|Species) + (1|sp_day_year) + (scale(parks_percent_change_from_baseline)|Country) + (1|IDLocality)+(1|sp_loc); >9/specie")

    mh03b <- lmer(scale(log(FID)) ~
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(Human) +
      (1 | Year) + (1 | weekday) + (scale(Human) | genus) + (1 | Species) + (1 | sp_day_year) +
      (scale(Human) | Country) + (1 | IDLocality) + (1 | sp_loc),
    data = dh[Nsp > 9], REML = FALSE
    )

    est_mh03b = est_out(mh03b, "03b) (1|Year) + (1|weeekday) + (scale(Human)|genus)+(1|Species)+(1|sp_day_year) + (scale(Human)|Country) + (1|IDLocality) +(1|sp_loc); >9/specie")

    mh03c <- lmer(scale(log(FID)) ~
      scale(log(SD)) +
      scale(log(FlockSize)) +
      scale(log(BodyMass)) +
      scale(sin(rad)) + scale(cos(rad)) +
      # scale(Day)+
      scale(Temp) +
      scale(Human) +
      (1|Year) + (1|genus) + (1|sp_day_year) + (scale(Human) | Country) + (1 | IDLocality) +(1|sp_loc),
    data = dh[Nsp > 9], REML = FALSE
    )
    est_mh03c = est_out(mh03c, "03c) (1|Year) + (1|genus) + (1|sp_day_year) + (scale(Human) | Country) + (1 | IDLocality) +(1|sp_loc); >9/specie")

    # export
      save(file = here::here("Data/Fig_S2_estimates.Rdata"), 
      est_m1a, est_m1b, est_m1c, est_m1d, est_m1e, est_m2a, est_m2b, est_m2c, est_m3a, est_m3b, est_m3c, 
      est_m01a, est_m01b, est_m01c, est_m02a, est_m02b, est_m02c, est_m03a, est_m03b, est_m03c, 
      est_mg01a, est_mg01b, est_mg01c, est_mg02a, est_mg02b, est_mg02c, est_mg03a, est_mg03b, est_mg03c,
      est_mh01a, est_mh01b, est_mh01c, est_mh02a, est_mh02b, est_mh02c, est_mh03a, est_mh03b, est_mh03c) # load(here::here("Data/Fig_S2_estimates.Rdata"))
     
     # prepare plot for Period
     xs = rbind(est_m1a, est_m1b, est_m1c, est_m1d, est_m1e, est_m2a, est_m2b, est_m2c, est_m3a, est_m3b, est_m3c)
     #gsub("scale\\(Covid\\)", "Period", "(scale(Covid)|Country)")
     xs[, model := gsub("scale\\(Covid\\)", "Period", xs$model)]
     xs[, model := gsub("Year", "year", xs$model)]
     xs[, model := gsub("Species", "species", xs$model)]
     xs[, model := gsub("sp_day_year", "species within day & year", xs$model)]
     xs[, model := gsub("IDLocality", "site", xs$model)]
     xs[, model := gsub("sp_loc", "species within site", xs$model)]

     gs2_ =
       ggplot(xs[predictor == "scale(Covid)"], aes(y = model, x = estimate, col = model)) +
       geom_vline(xintercept = 0, col = "grey30", lty = 3) +
       geom_errorbar(aes(xmin = lwr, xmax = upr, col = model), width = 0, position = position_dodge(width = 0.01)) +
       # ggtitle ("Sim based")+
       geom_point(position = position_dodge(width = 0.01)) +
       # scale_colour_brewer(type = 'qual', palette = 'Paired',guide = guide_legend(reverse = TRUE))+
       # scale_fill_brewer(type = 'qual', palette = 'Paired',guide = guide_legend(reverse = TRUE))+
       scale_color_viridis(discrete = TRUE, guide = guide_legend(reverse = TRUE)) +
       scale_fill_viridis(discrete = TRUE, guide = guide_legend(reverse = TRUE)) +
       scale_y_discrete(limits = rev) +
       coord_fixed(ratio = 0.05, xlim = c(-0.23, 0.15)) +
       # scale_shape(guide = guide_legend(reverse = TRUE)) +
       # scale_x_continuous(limits = c(-2, 2), expand = c(0, 0), breaks = seq(-2,2, by = 1), labels = seq(-2,2, by = 1)) +
       labs(y = NULL, x = "Period (before vs during shutdowns)", tag = "a)") + # title = "a)",Effect of Period (before/during shutdown)
       # ylim(c(0,100))+
       # coord_flip()+
       theme_bw() +
       theme(
         legend.position = "none",
         #plot.title.position = "plot",
         plot.subtitle = element_text(size = 7),
         plot.title = element_text(size = 7),
         plot.tag = element_text(size = 7),
         legend.title = element_text(size = 7),
         legend.text = element_text(size = 6),
         ## legend.spacing.y = unit(0.1, 'cm'),
         legend.key.height = unit(0.5, "line"),
         # plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r =0.5, unit =  "pt"),
         panel.grid = element_blank(),
         panel.border = element_blank(),
         panel.background = element_blank(),
         axis.line = element_line(colour = ax_lines, size = 0.25),
         axis.line.y = element_blank(),
         axis.ticks.y = element_blank(),
         axis.ticks.x = element_line(colour = ax_lines, size = 0.25),
         axis.ticks.length = unit(1, "pt"),
         axis.text.x = element_text(colour = "black", size = 6),
         axis.text.y = element_text(colour = "black", size = 7),
         axis.title = element_text(size = 7)
       )
     #gs2
     # ggsave(here::here('Outputs/Figure_Sy.png'),g, width = 30, height =5, units = 'cm')
     
     # prepare plot for Stringency
     xs0 = rbind(est_m01a, est_m01b, est_m01c, est_m02a, est_m02b, est_m02c, est_m03a, est_m03b, est_m03c)
     xs0[, model := gsub("scale\\(StringencyIndex\\)", "Stringency Index", model)]
     xs0[, model := gsub("Year", "year", model)]
     xs0[, model := gsub("Species", "species", model)]
     xs0[, model := gsub("sp_day_year", "species within day & year", model)]
     xs0[, model := gsub("IDLocality", "site", model)]
     xs0[, model := gsub("sp_loc", "species within site", model)]
     g0_ =
       ggplot(xs0[predictor == "scale(StringencyIndex)"], aes(y = model, x = estimate, col = model)) +
       geom_vline(xintercept = 0, col = "grey30", lty = 3) +
       geom_errorbar(aes(xmin = lwr, xmax = upr, col = model), width = 0, position = position_dodge(width = 0.01)) +
       # ggtitle ("Sim based")+
       geom_point(position = position_dodge(width = 0.01)) +
       # scale_colour_brewer(type = 'qual', palette = 'Paired',guide = guide_legend(reverse = TRUE))+
       # scale_fill_brewer(type = 'qual', palette = 'Paired',guide = guide_legend(reverse = TRUE))+
       scale_color_viridis(discrete = TRUE, guide = guide_legend(reverse = TRUE)) +
       scale_fill_viridis(discrete = TRUE, guide = guide_legend(reverse = TRUE)) +
       scale_y_discrete(limits = rev) +
       coord_fixed(ratio = 0.05, xlim = c(-0.23, 0.15)) +
       # scale_shape(guide = guide_legend(reverse = TRUE)) +
       # scale_x_continuous(limits = c(-2, 2), expand = c(0, 0), breaks = seq(-2,2, by = 1), labels = seq(-2,2, by = 1)) +
       labs(y = NULL, x = "Stringency index", tag = "b)") + # title = "b) Effect of ") +
       # ylim(c(0,100))+
       # coord_flip()+
       theme_bw() +
       theme(
         legend.position = "none",
         plot.subtitle = element_text(size = 7),
         plot.title = element_text(size = 7),
         plot.tag = element_text(size = 7),
         legend.title = element_text(size = 7),
         legend.text = element_text(size = 6),
         ## legend.spacing.y = unit(0.1, 'cm'),
         legend.key.height = unit(0.5, "line"),
         # plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r =0.5, unit =  "pt"),
         panel.grid = element_blank(),
         panel.border = element_blank(),
         panel.background = element_blank(),
         axis.line = element_line(colour = ax_lines, size = 0.25),
         axis.line.y = element_blank(),
         axis.ticks.y = element_blank(),
         axis.ticks.x = element_line(colour = ax_lines, size = 0.25),
         axis.ticks.length = unit(1, "pt"),
         axis.text.x = element_text(colour = "black", size = 6),
         axis.text.y = element_text(colour = "black", size = 7),
         axis.title = element_text(size = 7)
       )
     #g0
     # ggsave(here::here('Outputs/Figure_Sz.png'),g0, width = 30, height =5, units = 'cm')
     
     # prepare plot for Google
     xg0 = rbind(est_mg01a, est_mg01b, est_mg01c, est_mg02a, est_mg02b, est_mg02c, est_mg03a, est_mg03b, est_mg03c)
     xg0[, model := gsub("scale\\(parks_percent_change_from_baseline\\)", "Google Mobility", model)]
     xg0[, model := gsub("Year", "year", model)]
     xg0[, model := gsub("Species", "species", model)]
     xg0[, model := gsub("sp_day_year", "species within day & year", model)]
     xg0[, model := gsub("IDLocality", "site", model)]
     xg0[, model := gsub("sp_loc", "species within site", model)]
     gg0_ =
       ggplot(xg0[predictor == "scale(parks_percent_change_from_baseline)"], aes(y = model, x = estimate, col = model)) +
       geom_vline(xintercept = 0, col = "grey30", lty = 3) +
       geom_errorbar(aes(xmin = lwr, xmax = upr, col = model), width = 0, position = position_dodge(width = 0.01)) +
       # ggtitle ("Sim based")+
       geom_point(position = position_dodge(width = 0.01)) +
       # scale_colour_brewer(type = 'qual', palette = 'Paired',guide = guide_legend(reverse = TRUE))+
       # scale_fill_brewer(type = 'qual', palette = 'Paired',guide = guide_legend(reverse = TRUE))+
       scale_color_viridis(discrete = TRUE, guide = guide_legend(reverse = TRUE)) +
       scale_fill_viridis(discrete = TRUE, guide = guide_legend(reverse = TRUE)) +
       scale_y_discrete(limits = rev) +
       coord_fixed(ratio = 0.05, xlim = c(-0.23, 0.15)) +
       # scale_shape(guide = guide_legend(reverse = TRUE)) +
       # scale_x_continuous(limits = c(-2, 2), expand = c(0, 0), breaks = seq(-2,2, by = 1), labels = seq(-2,2, by = 1)) +
       labs(y = NULL, x = "Google Mobility", tag = "c)") + # title = "b) Effect of ") +
       # ylim(c(0,100))+
       # coord_flip()+
       theme_bw() +
       theme(
         legend.position = "none",
         plot.subtitle = element_text(size = 7),
         plot.title = element_text(size = 7),
         plot.tag = element_text(size = 7),
         legend.title = element_text(size = 7),
         legend.text = element_text(size = 6),
         ## legend.spacing.y = unit(0.1, 'cm'),
         legend.key.height = unit(0.5, "line"),
         # plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r =0.5, unit =  "pt"),
         panel.grid = element_blank(),
         panel.border = element_blank(),
         panel.background = element_blank(),
         axis.line = element_line(colour = ax_lines, size = 0.25),
         axis.line.y = element_blank(),
         axis.ticks.y = element_blank(),
         axis.ticks.x = element_line(colour = ax_lines, size = 0.25),
         axis.ticks.length = unit(1, "pt"),
         axis.text.x = element_text(colour = "black", size = 6),
         axis.text.y = element_text(colour = "black", size = 7),
         axis.title = element_text(size = 7)
       )
     #gg0
     # ggsave(here::here('Outputs/Figure_Sz.png'),g0, width = 30, height =5, units = 'cm')

     # prepare plot for number of humans
     xh0 = rbind(est_mh01a, est_mh01b, est_mh01c, est_mh02a, est_mh02b, est_mh02c, est_mh03a, est_mh03b, est_mh03c)
     xh0[, model := gsub("scale\\(Human\\)", "# of humans", model)]
     xh0[, model := gsub("Year", "year", model)]
     xh0[, model := gsub("Species", "species", model)]
     xh0[, model := gsub("sp_day_year", "species within day & year", model)]
     xh0[, model := gsub("IDLocality", "site", model)]
     xh0[, model := gsub("sp_loc", "species within site", model)]
     gh0_ =
       ggplot(xh0[predictor == "scale(Human)"], aes(y = model, x = estimate, col = model)) +
       geom_vline(xintercept = 0, col = "grey30", lty = 3) +
       geom_errorbar(aes(xmin = lwr, xmax = upr, col = model), width = 0, position = position_dodge(width = 0.01)) +
       # ggtitle ("Sim based")+
       geom_point(position = position_dodge(width = 0.01)) +
       # scale_colour_brewer(type = 'qual', palette = 'Paired',guide = guide_legend(reverse = TRUE))+
       # scale_fill_brewer(type = 'qual', palette = 'Paired',guide = guide_legend(reverse = TRUE))+
       scale_color_viridis(discrete = TRUE, guide = guide_legend(reverse = TRUE)) +
       scale_fill_viridis(discrete = TRUE, guide = guide_legend(reverse = TRUE)) +
       scale_y_discrete(limits = rev) +
       coord_fixed(ratio = 0.05, xlim = c(-0.23, 0.15)) +
       # scale_shape(guide = guide_legend(reverse = TRUE)) +
       # scale_x_continuous(limits = c(-2, 2), expand = c(0, 0), breaks = seq(-2,2, by = 1), labels = seq(-2,2, by = 1)) +
       labs(y = NULL, x = "# of humans\n[Standardised effect sizes on\nflight initiation distances]", tag = "d)") + # title = "b) Effect of ") +
       # ylim(c(0,100))+
       # coord_flip()+
       theme_bw() +
       theme(
         legend.position = "none",
         plot.subtitle = element_text(size = 7),
         plot.title = element_text(size = 7),
         plot.tag = element_text(size = 7),
         legend.title = element_text(size = 7),
         legend.text = element_text(size = 6),
         ## legend.spacing.y = unit(0.1, 'cm'),
         legend.key.height = unit(0.5, "line"),
         # plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r =0.5, unit =  "pt"),
         panel.grid = element_blank(),
         panel.border = element_blank(),
         panel.background = element_blank(),
         axis.line = element_line(colour = ax_lines, size = 0.25),
         axis.line.y = element_blank(),
         axis.ticks.y = element_blank(),
         axis.ticks.x = element_line(colour = ax_lines, size = 0.25),
         axis.ticks.length = unit(1, "pt"),
         axis.text.x = element_text(colour = "black", size = 6),
         axis.text.y = element_text(colour = "black", size = 7),
         axis.title = element_text(size = 7)
       )
     #gg0
     # ggsave(here::here('Outputs/Figure_Sz.png'),g0, width = 30, height =5, units = 'cm')

     # combine
     if(save_plot==TRUE){
     ggsave(here::here("Outputs/Fig_S1_rev_v7.png"), rbind(ggplotGrob(gs2_), ggplotGrob(g0_), ggplotGrob(gg0_), ggplotGrob(gh0_)), width = 30, height = 20, units = "cm")
     }
     
     grid.draw(rbind(ggplotGrob(gs2_), ggplotGrob(g0_), ggplotGrob(gg0_), ggplotGrob(gh0_)))

Figure S1 | Comparing estimates from alternative models. Changes in avian tolerance towards humans in response to (a) Period (before vs during the COVID-19 shutdowns) (b) stringency of governmental measures, (c) Google Mobility and (d) number of humans during an escape distance trial. The dots with horizontal lines represent the estimated standardised effect size and their 95% confidence intervals based on the joint posterior distribution of 5,000 simulated values generated by the sim function from the arm R-package (Gelman et al. 2016) from the output of the mixed models (for details see Table S2). The name of each effect size highlights the corresponding model in Table S2a for (a), Table S2b for (b), Table S2c for (c) and Table S2d for (d), the random structure of the specific model, if applicable, the condition used to reduce the dataset, and sample size. Depicted are effect sizes based on full (01) and reduced datasets with ≥5 (02) or ≥10 observations per species and period (03). For plots of model assumptions see below. Note that effect sizes are small and estimates close to zero.

Table S2a | Alternative models on escape distance given Period

    m1a_ = m_out(name = "Table S2a - 1a", dep = "Escape distance", model = m1a, nsim = 5000)
    m1b_ = m_out(name = "Table S2a - 1b", dep = "Escape distance", model = m1b, nsim = 5000)
    m1c_ = m_out(name = "Table S2a - 1c", dep = "Escape distance", model = m1c, nsim = 5000)
    m1d_ = m_out(name = "Table S2a - 1d", dep = "Escape distance", model = m1d, nsim = 5000)
    m1e_ = m_out(name = "Table S2a - 1e", dep = "Escape distance", model = m1e, nsim = 5000)

    m2a_ = m_out(name = "Table S2a - 2a", dep = "Escape distance", model = m2a, nsim = 5000)
    m2b_ = m_out(name = "Table S2a - 2b", dep = "Escape distance", model = m2b, nsim = 5000)
    m2c_ = m_out(name = "Table S2a - 2c", dep = "Escape distance", model = m2c, nsim = 5000)
    m3a_ = m_out(name = "Table S2a - 3a", dep = "Escape distance", model = m3a, nsim = 5000)
    m3b_ = m_out(name = "Table S2a - 3b", dep = "Escape distance", model = m3b, nsim = 5000)
    m3c_ = m_out(name = "Table S2a - 3c", dep = "Escape distance", model = m3c, nsim = 5000)
     
    out1 = rbind(m1a_, m1b_, m1c_, m1d_, m1e_, m2a_, m2b_, m2c_, m3a_, m3b_, m3c_, fill = TRUE)
    out1[is.na(out1)] = ""
    out1[, effect := gsub("scale\\(Covid\\)", "Period", effect)]
    out1[, effect := gsub("scale\\(Year\\)", "year", effect)]
    out1[, effect := gsub("scale\\(log\\(SD\\)\\)", "starting distance (ln)", effect)]
    out1[, effect := gsub("scale\\(Temp\\)", "temperature", effect)]
    out1[, effect := gsub("scale\\(log\\(FlockSize\\)\\)", "flock size (ln)", effect)]
    out1[, effect := gsub("scale\\(log\\(BodyMass\\)\\)", "body mass (ln)", effect)]
    out1[, effect := gsub("scale\\(sin\\(rad\\)\\)", "time (sine of radians)", effect)]
    out1[, effect := gsub("scale\\(cos\\(rad\\)\\)", "time (cosine of radians)", effect)]
    out1[, effect := gsub("Species", "species", effect)]
    out1[, effect := gsub("Country", "country", effect)]
    out1[, effect := gsub("Year", "year", effect)]
    out1[, effect := gsub("sp_day_year", "species within day & year", effect)]
    out1[, effect := gsub("IDLocality", "site", effect)]
    out1[, effect := gsub("sp_loc", "species within site", effect)]
    out1[type == "random" & grepl("Period", effect, fixed = TRUE), effect := paste("Period (slope) |", gsub(" Period", "", effect))]

    out1$R2_mar=out1$R2_con=NULL
    fwrite(file = here::here("Outputs/Table_S2a.csv"), out1)

    out1$response = out1$error_structure = NULL
    out1[model != "", model := paste0('0',substring(model, 13))]
    setnames(out1, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
    out1 %>%
       kbl() %>%
       kable_paper("hover", full_width = F)
model N type effect estimate lower upper
01a 6369 fixed (Intercept) 0.08 -0.136 0.293
fixed starting distance (ln) 0.477 0.453 0.501
fixed flock size (ln) -0.008 -0.027 0.011
fixed body mass (ln) 0.047 -0.019 0.113
fixed time (sine of radians) 0.022 -0.006 0.049
fixed time (cosine of radians) 0.029 0.005 0.052
fixed temperature -0.001 -0.029 0.029
fixed Period -0.032 -0.195 0.124
random species within day & year (Intercept) 8% 6% 9%
random species within site (Intercept) 5% 4% 5%
random site (Intercept) 1% 0% 5%
random Period (slope) | site 1% 0% 5%
random species (Intercept) 9% 8% 8%
random genus (Intercept) 6% 6% 6%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 1% -3% 5%
random Period (slope) | country 1% -3% 5%
random year (Intercept) 3% 1% 4%
random Residual 65% 51% 76%
01b 6369 fixed (Intercept) 0.071 -0.153 0.3
fixed starting distance (ln) 0.478 0.455 0.502
fixed flock size (ln) -0.007 -0.026 0.011
fixed body mass (ln) 0.047 -0.019 0.113
fixed time (sine of radians) 0.021 -0.008 0.048
fixed time (cosine of radians) 0.027 0.005 0.05
fixed temperature -0.001 -0.029 0.028
fixed Period -0.048 -0.204 0.113
random species within day & year (Intercept) 12% 7% 14%
random species within site (Intercept) 0% 0% 1%
random Period (slope) | species within site 0% 0% 1%
random site (Intercept) 2% 0% 5%
random Period (slope) | site 2% 0% 5%
random species (Intercept) 0% -1% 8%
random Period (slope) | species 0% -1% 8%
random genus (Intercept) 0% 0% 5%
random Period (slope) | genus 0% 0% 5%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 1% -4% 6%
random Period (slope) | country 1% -4% 6%
random year (Intercept) 3% 2% 4%
random Residual 79% 42% 93%
01c 6369 fixed (Intercept) 0.012 -0.155 0.179
fixed starting distance (ln) 0.493 0.47 0.517
fixed flock size (ln) -0.018 -0.037 0
fixed body mass (ln) 0.024 -0.007 0.055
fixed time (sine of radians) 0.014 -0.015 0.043
fixed time (cosine of radians) 0.027 0.005 0.051
fixed temperature -0.004 -0.033 0.027
fixed Period -0.043 -0.208 0.132
random species within day & year (Intercept) 12% 7% 13%
random species within site (Intercept) 1% 0% 12%
random Period (slope) | species within site 1% 0% 12%
random site (Intercept) 1% 1% 6%
random Period (slope) | site 1% 1% 6%
random Period (slope) | species 1% 1% 1%
random Period (slope) | genus 0% 0% 0%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 1% -2% 4%
random Period (slope) | country 1% -2% 4%
random year (Intercept) 3% 2% 4%
random Residual 77% 46% 87%
01d 6369 fixed (Intercept) 0.084 -0.124 0.295
fixed starting distance (ln) 0.476 0.452 0.499
fixed flock size (ln) -0.008 -0.027 0.011
fixed body mass (ln) 0.047 -0.02 0.115
fixed time (sine of radians) 0.022 -0.006 0.049
fixed time (cosine of radians) 0.028 0.006 0.052
fixed temperature 0 -0.028 0.028
fixed Period -0.032 -0.198 0.13
random species within day & year (Intercept) 8% 6% 9%
random species within site (Intercept) 0% 0% 4%
random Period (slope) | species within site 0% 0% 4%
random site (Intercept) 1% 0% 5%
random Period (slope) | site 1% 0% 5%
random species (Intercept) 10% 9% 10%
random genus (Intercept) 7% 6% 6%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 1% -3% 5%
random Period (slope) | country 1% -3% 5%
random year (Intercept) 3% 2% 4%
random Residual 66% 48% 79%
01e 6369 fixed (Intercept) 0.079 -0.128 0.284
fixed starting distance (ln) 0.478 0.454 0.501
fixed flock size (ln) -0.008 -0.028 0.011
fixed body mass (ln) 0.048 -0.017 0.115
fixed time (sine of radians) 0.021 -0.007 0.05
fixed time (cosine of radians) 0.024 0.001 0.047
fixed temperature -0.005 -0.033 0.022
fixed Period -0.032 -0.208 0.143
random species within day & year (Intercept) 7% 6% 8%
random species within site (Intercept) 5% 4% 5%
random site (Intercept) 6% 6% 6%
random species (Intercept) 8% 8% 9%
random genus (Intercept) 6% 5% 6%
random weekday (Intercept) 0% 0% 1%
random country (Intercept) 1% -3% 5%
random Period (slope) | country 1% -3% 5%
random year (Intercept) 2% 1% 4%
random Residual 62% 52% 71%
02a 5261 fixed (Intercept) 0.162 -0.18 0.518
fixed starting distance (ln) 0.463 0.437 0.489
fixed flock size (ln) -0.01 -0.03 0.011
fixed body mass (ln) -0.013 -0.121 0.094
fixed time (sine of radians) 0.027 -0.002 0.057
fixed time (cosine of radians) 0.036 0.012 0.061
fixed temperature -0.005 -0.038 0.027
fixed Period -0.033 -0.206 0.142
random species within day & year (Intercept) 7% 4% 9%
random species within site (Intercept) 3% 2% 4%
random site (Intercept) 1% -1% 2%
random Period (slope) | site 1% -1% 2%
random species (Intercept) 10% 8% 9%
random genus (Intercept) 5% 4% 4%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 3% -5% 20%
random Period (slope) | country 3% -5% 20%
random year (Intercept) 3% 2% 3%
random Residual 64% 34% 84%
02b 5261 fixed (Intercept) 0.162 -0.191 0.503
fixed starting distance (ln) 0.462 0.435 0.488
fixed flock size (ln) -0.01 -0.031 0.01
fixed body mass (ln) -0.01 -0.123 0.1
fixed time (sine of radians) 0.027 -0.001 0.057
fixed time (cosine of radians) 0.037 0.012 0.062
fixed temperature -0.005 -0.038 0.028
fixed Period -0.033 -0.204 0.142
random species within day & year (Intercept) 9% 4% 11%
random species within site (Intercept) 0% 0% 2%
random Period (slope) | species within site 0% 0% 2%
random site (Intercept) 1% -1% 2%
random Period (slope) | site 1% -1% 2%
random species (Intercept) 0% -1% 5%
random Period (slope) | species 0% -1% 5%
random genus (Intercept) 0% 0% 6%
random Period (slope) | genus 0% 0% 6%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 3% -6% 17%
random Period (slope) | country 3% -6% 17%
random year (Intercept) 4% 2% 3%
random Residual 78% 30% 100%
02c 5261 fixed (Intercept) 0.152 -0.189 0.498
fixed starting distance (ln) 0.465 0.438 0.491
fixed flock size (ln) -0.01 -0.031 0.01
fixed body mass (ln) -0.011 -0.117 0.098
fixed time (sine of radians) 0.027 -0.002 0.056
fixed time (cosine of radians) 0.032 0.007 0.056
fixed temperature -0.011 -0.042 0.02
fixed Period -0.035 -0.213 0.142
random species within day & year (Intercept) 7% 5% 9%
random species within site (Intercept) 3% 2% 4%
random site (Intercept) 4% 3% 4%
random species (Intercept) 8% 7% 7%
random genus (Intercept) 6% 4% 6%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 2% -6% 17%
random Period (slope) | country 2% -6% 17%
random year (Intercept) 3% 2% 4%
random Residual 63% 39% 81%
03a 5107 fixed (Intercept) 0.13 -0.213 0.479
fixed starting distance (ln) 0.462 0.435 0.49
fixed flock size (ln) -0.01 -0.031 0.01
fixed body mass (ln) 0.004 -0.107 0.114
fixed time (sine of radians) 0.027 -0.003 0.057
fixed time (cosine of radians) 0.034 0.008 0.059
fixed temperature -0.007 -0.039 0.026
fixed Period -0.032 -0.208 0.139
random species within day & year (Intercept) 7% 4% 9%
random species within site (Intercept) 3% 2% 4%
random site (Intercept) 1% -1% 2%
random Period (slope) | site 1% -1% 2%
random species (Intercept) 21% 16% 18%
random genus (Intercept) 0% 0% 0%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 2% -5% 19%
random Period (slope) | country 2% -5% 19%
random year (Intercept) 3% 2% 3%
random Residual 60% 32% 79%
03b 5107 fixed (Intercept) 0.143 -0.193 0.487
fixed starting distance (ln) 0.461 0.434 0.488
fixed flock size (ln) -0.01 -0.03 0.011
fixed body mass (ln) 0.012 -0.106 0.131
fixed time (sine of radians) 0.027 -0.002 0.057
fixed time (cosine of radians) 0.034 0.008 0.059
fixed temperature -0.007 -0.041 0.026
fixed Period -0.03 -0.21 0.143
random species within day & year (Intercept) 9% 3% 11%
random species within site (Intercept) 0% 0% 2%
random Period (slope) | species within site 0% 0% 2%
random site (Intercept) 1% -1% 2%
random Period (slope) | site 1% -1% 2%
random species (Intercept) 0% -1% 9%
random Period (slope) | species 0% -1% 9%
random genus (Intercept) 0% 0% 3%
random Period (slope) | genus 0% 0% 3%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 3% -5% 16%
random Period (slope) | country 3% -5% 16%
random year (Intercept) 4% 2% 3%
random Residual 79% 28% 100%
03c 5107 fixed (Intercept) 0.123 -0.224 0.49
fixed starting distance (ln) 0.463 0.436 0.491
fixed flock size (ln) -0.01 -0.031 0.011
fixed body mass (ln) 0.006 -0.105 0.117
fixed time (sine of radians) 0.026 -0.003 0.056
fixed time (cosine of radians) 0.029 0.004 0.054
fixed temperature -0.014 -0.046 0.018
fixed Period -0.029 -0.2 0.156
random species within day & year (Intercept) 7% 5% 9%
random species within site (Intercept) 3% 2% 4%
random site (Intercept) 5% 3% 5%
random species (Intercept) 15% 11% 15%
random genus (Intercept) 0% 0% 0%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 2% -6% 18%
random Period (slope) | country 2% -6% 18%
random year (Intercept) 3% 2% 4%
random Residual 62% 38% 78%

Note that (1a) model is the one reported in the main text.


Table S2b | Alternative models on escape distance given Stringency

    m01a_ = m_out(name = "Table S2b - 1a", dep = "Escape distance", model = m01a, nsim = 5000)
    m01b_ = m_out(name = "Table S2b - 1b", dep = "Escape distance", model = m01b, nsim = 5000)
    m01c_ = m_out(name = "Table S2b - 1c", dep = "Escape distance", model = m01c, nsim = 5000)

    m02a_ = m_out(name = "Table S2b - 2a", dep = "Escape distance", model = m02a, nsim = 5000)
    m02b_ = m_out(name = "Table S2b - 2b", dep = "Escape distance", model = m02b, nsim = 5000)
    m02c_ = m_out(name = "Table S2b - 2c", dep = "Escape distance", model = m02c, nsim = 5000)

    m03a_ = m_out(name = "Table S2b - 3a", dep = "Escape distance", model = m03a, nsim = 5000)
    m03b_ = m_out(name = "Table S2b - 3b", dep = "Escape distance", model = m03b, nsim = 5000)
    m03c_ = m_out(name = "Table S2b - 3c", dep = "Escape distance", model = m03c, nsim = 5000)

    out2 = rbind(m01a_, m01b_, m01c_, m02a_, m02b_, m02c_, m03a_, m03b_, m03c_, fill = TRUE)
    out2[is.na(out2)] = ""
    out2[, effect := gsub("scale\\(StringencyIndex\\)", "Stringency index", effect)]
    out2[, effect := gsub("scale\\(Year\\)", "year", effect)]
    out2[, effect := gsub("scale\\(log\\(SD\\)\\)", "starting distance (ln)", effect)]
    out2[, effect := gsub("scale\\(Temp\\)", "temperature", effect)]
    out2[, effect := gsub("scale\\(log\\(FlockSize\\)\\)", "flock size (ln)", effect)]
    out2[, effect := gsub("scale\\(log\\(BodyMass\\)\\)", "body mass (ln)", effect)]
    out2[, effect := gsub("scale\\(sin\\(rad\\)\\)", "time (sine of radians)", effect)]
    out2[, effect := gsub("scale\\(cos\\(rad\\)\\)", "time (cosine of radians)", effect)]
    out2[, effect := gsub("Species", "species", effect)]
    out2[, effect := gsub("Country", "country", effect)]
    out2[, effect := gsub("Year", "year", effect)]
    out2[, effect := gsub("sp_day_year", "species within day & year", effect)]
    out2[, effect := gsub("IDLocality", "site", effect)]
    out2[, effect := gsub("sp_loc", "species within site", effect)]
    out2[type == "random" & grepl("Stringency index", effect, fixed = TRUE), effect := paste("Stringency index (slope) |", gsub(" Stringency index", "", effect))]
    out2$R2_mar = out2$R2_con = NULL

    fwrite(file = here::here("Outputs/Table_S2b.csv"), out2)

    out2$response = out2$error_structure = NULL
    out2[model != "", model := paste0("0", substring(model, 13))]
    setnames(out2, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
    out2 %>%
      kbl() %>%
      kable_paper("hover", full_width = F)
model N type effect estimate lower upper
01a 3676 fixed (Intercept) -0.077 -0.326 0.173
fixed year 0.02 -0.028 0.066
fixed starting distance (ln) 0.492 0.459 0.524
fixed flock size (ln) -0.003 -0.029 0.024
fixed body mass (ln) 0.023 -0.045 0.09
fixed time (sine of radians) -0.019 -0.061 0.022
fixed time (cosine of radians) -0.004 -0.04 0.032
fixed temperature -0.007 -0.048 0.035
fixed Stringency index 0.016 -0.153 0.175
random species within day & year (Intercept) 5% 3% 7%
random species within site (Intercept) 5% 3% 6%
random species (Intercept) 7% 6% 9%
random site (Intercept) 8% 7% 9%
random genus (Intercept) 4% 4% 4%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 2% -16% 16%
random Stringency index (slope) | country 2% -16% 16%
random Residual 67% 45% 96%
01b 3676 fixed (Intercept) -0.07 -0.334 0.178
fixed year 0.019 -0.029 0.067
fixed starting distance (ln) 0.492 0.46 0.524
fixed flock size (ln) -0.003 -0.029 0.024
fixed body mass (ln) 0.017 -0.05 0.084
fixed time (sine of radians) -0.019 -0.061 0.022
fixed time (cosine of radians) -0.004 -0.04 0.031
fixed temperature -0.007 -0.049 0.036
fixed Stringency index 0.006 -0.162 0.171
random species within day & year (Intercept) 5% 3% 7%
random species within site (Intercept) 5% 3% 7%
random species (Intercept) 7% 5% 8%
random site (Intercept) 8% 6% 10%
random genus (Intercept) 0% -1% 4%
random Stringency index (slope) | genus 0% -1% 4%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 2% -15% 15%
random Stringency index (slope) | country 2% -15% 15%
random Residual 70% 44% 100%
01c 3676 fixed (Intercept) -0.107 -0.281 0.066
fixed year -0.003 -0.052 0.045
fixed starting distance (ln) 0.55 0.518 0.581
fixed flock size (ln) -0.023 -0.049 0.004
fixed body mass (ln) -0.024 -0.053 0.005
fixed time (sine of radians) -0.039 -0.081 0.004
fixed time (cosine of radians) 0.005 -0.031 0.042
fixed temperature 0.004 -0.038 0.045
fixed Stringency index 0.021 -0.133 0.179
random site (Intercept) 11% 10% 11%
random country (Intercept) 1% -7% 8%
random Stringency index (slope) | country 1% -7% 8%
random Residual 88% 74% 103%
02a 3573 fixed (Intercept) -0.156 -0.445 0.137
fixed year 0.022 -0.026 0.072
fixed starting distance (ln) 0.482 0.45 0.515
fixed flock size (ln) 0.003 -0.024 0.03
fixed body mass (ln) -0.024 -0.101 0.051
fixed time (sine of radians) -0.019 -0.061 0.023
fixed time (cosine of radians) -0.007 -0.043 0.028
fixed temperature -0.008 -0.05 0.035
fixed Stringency index 0.018 -0.147 0.193
random species within day & year (Intercept) 5% 3% 7%
random species within site (Intercept) 4% 3% 7%
random site (Intercept) 7% 5% 9%
random species (Intercept) 11% 8% 14%
random genus (Intercept) 2% 2% 2%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 3% -22% 20%
random Stringency index (slope) | country 3% -22% 20%
random Residual 65% 39% 104%
02b 3573 fixed (Intercept) -0.154 -0.447 0.144
fixed year 0.021 -0.029 0.07
fixed starting distance (ln) 0.484 0.452 0.517
fixed flock size (ln) 0.003 -0.023 0.029
fixed body mass (ln) -0.031 -0.107 0.046
fixed time (sine of radians) -0.02 -0.06 0.023
fixed time (cosine of radians) -0.007 -0.043 0.029
fixed temperature -0.008 -0.05 0.035
fixed Stringency index 0.019 -0.152 0.191
random species within day & year (Intercept) 5% 3% 7%
random species within site (Intercept) 4% 3% 7%
random site (Intercept) 7% 5% 9%
random species (Intercept) 11% 8% 13%
random genus (Intercept) 0% -1% 2%
random Stringency index (slope) | genus 0% -1% 2%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 3% -20% 19%
random Stringency index (slope) | country 3% -20% 19%
random Residual 67% 38% 106%
02c 3573 fixed (Intercept) -0.11 -0.283 0.067
fixed year -0.001 -0.05 0.047
fixed starting distance (ln) 0.543 0.512 0.576
fixed flock size (ln) -0.018 -0.045 0.009
fixed body mass (ln) -0.027 -0.056 0.001
fixed time (sine of radians) -0.038 -0.079 0.003
fixed time (cosine of radians) 0.001 -0.035 0.039
fixed temperature 0.003 -0.038 0.045
fixed Stringency index 0.024 -0.142 0.188
random site (Intercept) 10% 10% 10%
random country (Intercept) 1% -7% 8%
random Stringency index (slope) | country 1% -7% 8%
random Residual 88% 73% 105%
03a 3425 fixed (Intercept) -0.14 -0.461 0.166
fixed year 0.027 -0.022 0.077
fixed starting distance (ln) 0.481 0.447 0.514
fixed flock size (ln) 0.002 -0.025 0.029
fixed body mass (ln) 0.023 -0.067 0.11
fixed time (sine of radians) -0.012 -0.053 0.031
fixed time (cosine of radians) -0.009 -0.046 0.029
fixed temperature -0.011 -0.056 0.032
fixed Stringency index 0.016 -0.151 0.191
random species within day & year (Intercept) 5% 3% 7%
random species within site (Intercept) 5% 3% 7%
random site (Intercept) 8% 5% 10%
random species (Intercept) 9% 7% 10%
random genus (Intercept) 3% 3% 3%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 2% -21% 20%
random Stringency index (slope) | country 2% -21% 20%
random Residual 67% 39% 105%
03b 3425 fixed (Intercept) -0.135 -0.445 0.179
fixed year 0.027 -0.023 0.077
fixed starting distance (ln) 0.481 0.448 0.514
fixed flock size (ln) 0.001 -0.025 0.029
fixed body mass (ln) 0.02 -0.064 0.11
fixed time (sine of radians) -0.012 -0.055 0.031
fixed time (cosine of radians) -0.009 -0.046 0.028
fixed temperature -0.011 -0.054 0.031
fixed Stringency index 0.015 -0.156 0.183
random species within day & year (Intercept) 5% 3% 7%
random species within site (Intercept) 4% 3% 7%
random site (Intercept) 8% 5% 11%
random species (Intercept) 10% 7% 11%
random genus (Intercept) 0% 0% 2%
random Stringency index (slope) | genus 0% 0% 2%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 3% -23% 21%
random Stringency index (slope) | country 3% -23% 21%
random Residual 67% 36% 110%
03c 3425 fixed (Intercept) -0.107 -0.291 0.071
fixed year 0.005 -0.043 0.055
fixed starting distance (ln) 0.541 0.508 0.574
fixed flock size (ln) -0.019 -0.047 0.008
fixed body mass (ln) -0.019 -0.049 0.011
fixed time (sine of radians) -0.03 -0.073 0.011
fixed time (cosine of radians) -0.001 -0.039 0.037
fixed temperature -0.002 -0.046 0.041
fixed Stringency index 0.02 -0.137 0.182
random site (Intercept) 11% 11% 11%
random country (Intercept) 1% -8% 8%
random Stringency index (slope) | country 1% -8% 8%
random Residual 87% 73% 105%

Note that (1a) model is the one reported in the Fig. S6.

Table S2c | Alternative models on escape distance given Google Mobility

    # google
     mg01a_ = m_out(name = "Table S2c - 1a", dep = "Escape distance", model = mg01a, nsim = 5000)
     mg01b_ = m_out(name = "Table S2c - 1b", dep = "Escape distance", model = mg01b, nsim = 5000)
     mg01c_ = m_out(name = "Table S2c - 1c", dep = "Escape distance", model = mg01c, nsim = 5000)

     mg02a_ = m_out(name = "Table S2c - 2a", dep = "Escape distance", model = mg02a, nsim = 5000)
     mg02b_ = m_out(name = "Table S2c - 2b", dep = "Escape distance", model = mg02b, nsim = 5000)
     mg02c_ = m_out(name = "Table S2c - 2c", dep = "Escape distance", model = mg02c, nsim = 5000)

     mg03a_ = m_out(name = "Table S2c - 3a", dep = "Escape distance", model = mg03a, nsim = 5000)
     mg03b_ = m_out(name = "Table S2c - 3b", dep = "Escape distance", model = mg03b, nsim = 5000)
     mg03c_ = m_out(name = "Table S2c - 3c", dep = "Escape distancey", model = mg03c, nsim = 5000)

     out3 = rbind(mg01a_, mg01b_, mg01c_, mg02a_, mg02b_, mg02c_, mg03a_, mg03b_, mg03c_, fill = TRUE)
     out3[is.na(out3)] = ""
      out3[, effect := gsub("scale\\(parks_percent_change_from_baseline\\)", "Google Mobility", effect)]
      out3[, effect := gsub("scale\\(Year\\)", "year", effect)]
      out3[, effect := gsub("scale\\(log\\(SD\\)\\)", "starting distance (ln)", effect)]
      out3[, effect := gsub("scale\\(Temp\\)", "temperature", effect)]
      out3[, effect := gsub("scale\\(log\\(FlockSize\\)\\)", "flock size (ln)", effect)]
      out3[, effect := gsub("scale\\(log\\(BodyMass\\)\\)", "body mass (ln)", effect)]
      out3[, effect := gsub("scale\\(sin\\(rad\\)\\)", "time (sine of radians)", effect)]
      out3[, effect := gsub("scale\\(cos\\(rad\\)\\)", "time (cosine of radians)", effect)]
       out3[, effect := gsub("Species", "species", effect)]
       out3[, effect := gsub("Country", "country", effect)]
       out3[, effect := gsub("Year", "year", effect)]
       out3[, effect := gsub("sp_day_year", "species within day & year", effect)]
       out3[, effect := gsub("IDLocality", "site", effect)]
       out3[, effect := gsub("sp_loc", "species within site", effect)]
       out3[type == "random" & grepl("Google Mobility", effect, fixed = TRUE), effect := paste("Google Mobility (slope) |", gsub(" Google Mobility", "", effect))]
       out3$R2_mar = out3$R2_con = NULL
     fwrite(file = here::here("Outputs/Table_S2c.csv"), out3)
     out3$response = out3$error_structure = NULL
     out3[model != "", model := paste0("0", substring(model, 13))]
     setnames(out3, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
     out3 %>%
          kbl() %>%
          kable_paper("hover", full_width = F)
model N type effect estimate lower upper
01a 3644 fixed (Intercept) 0.024 -0.094 0.143
fixed year 0.018 -0.022 0.06
fixed starting distance (ln) 0.499 0.467 0.529
fixed flock size (ln) -0.001 -0.027 0.025
fixed body mass (ln) 0.023 -0.044 0.089
fixed time (sine of radians) -0.009 -0.051 0.032
fixed time (cosine of radians) 0.011 -0.023 0.045
fixed temperature 0.021 -0.016 0.059
fixed Google Mobility -0.1 -0.231 0.028
random species within day & year (Intercept) 6% 5% 6%
random species within site (Intercept) 5% 4% 5%
random species (Intercept) 7% 7% 8%
random site (Intercept) 9% 8% 10%
random genus (Intercept) 3% 3% 4%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 1% -3% 4%
random Google Mobility (slope) | country 1% -3% 4%
random Residual 68% 61% 78%
01b 3644 fixed (Intercept) 0.024 -0.091 0.141
fixed year 0.019 -0.022 0.06
fixed starting distance (ln) 0.498 0.468 0.53
fixed flock size (ln) -0.001 -0.027 0.025
fixed body mass (ln) 0.026 -0.039 0.093
fixed time (sine of radians) -0.009 -0.051 0.031
fixed time (cosine of radians) 0.01 -0.023 0.044
fixed temperature 0.021 -0.016 0.059
fixed Google Mobility -0.102 -0.231 0.029
random species within day & year (Intercept) 6% 5% 6%
random species within site (Intercept) 5% 4% 5%
random species (Intercept) 7% 7% 7%
random site (Intercept) 9% 9% 9%
random genus (Intercept) 0% -1% 4%
random Google Mobility (slope) | genus 0% -1% 4%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 1% -4% 4%
random Google Mobility (slope) | country 1% -4% 4%
random Residual 71% 59% 81%
01c 3644 fixed (Intercept) -0.056 -0.144 0.029
fixed year 0.013 -0.026 0.051
fixed starting distance (ln) 0.559 0.527 0.591
fixed flock size (ln) -0.022 -0.048 0.004
fixed body mass (ln) -0.024 -0.053 0.005
fixed time (sine of radians) -0.033 -0.073 0.009
fixed time (cosine of radians) 0.021 -0.014 0.055
fixed temperature 0.032 -0.006 0.069
fixed Google Mobility -0.085 -0.21 0.032
random site (Intercept) 11% 10% 12%
random country (Intercept) 0% -1% 2%
random Google Mobility (slope) | country 0% -1% 2%
random Residual 88% 83% 92%
02a 3545 fixed (Intercept) -0.029 -0.167 0.109
fixed year 0.019 -0.022 0.062
fixed starting distance (ln) 0.49 0.459 0.523
fixed flock size (ln) 0.005 -0.022 0.03
fixed body mass (ln) -0.019 -0.092 0.054
fixed time (sine of radians) -0.01 -0.051 0.033
fixed time (cosine of radians) 0.009 -0.025 0.044
fixed temperature 0.022 -0.016 0.059
fixed Google Mobility -0.097 -0.231 0.039
random species within day & year (Intercept) 6% 5% 6%
random species within site (Intercept) 4% 4% 5%
random site (Intercept) 9% 8% 9%
random species (Intercept) 10% 9% 11%
random genus (Intercept) 2% 1% 2%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 0% -5% 5%
random Google Mobility (slope) | country 0% -5% 5%
random Residual 69% 59% 80%
02b 3545 fixed (Intercept) -0.036 -0.169 0.095
fixed year 0.019 -0.024 0.061
fixed starting distance (ln) 0.49 0.459 0.523
fixed flock size (ln) 0.005 -0.023 0.031
fixed body mass (ln) -0.029 -0.1 0.038
fixed time (sine of radians) -0.01 -0.052 0.032
fixed time (cosine of radians) 0.01 -0.025 0.044
fixed temperature 0.021 -0.018 0.06
fixed Google Mobility -0.092 -0.227 0.045
random species within day & year (Intercept) 5% 5% 6%
random species within site (Intercept) 4% 4% 5%
random site (Intercept) 8% 8% 8%
random species (Intercept) 16% 15% 17%
random genus (Intercept) 0% 0% 0%
random Google Mobility (slope) | genus 0% 0% 0%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 0% -5% 4%
random Google Mobility (slope) | country 0% -5% 4%
random Residual 66% 56% 77%
02c 3545 fixed (Intercept) -0.055 -0.142 0.029
fixed year 0.014 -0.024 0.054
fixed starting distance (ln) 0.552 0.518 0.584
fixed flock size (ln) -0.017 -0.044 0.01
fixed body mass (ln) -0.026 -0.056 0.004
fixed time (sine of radians) -0.033 -0.074 0.009
fixed time (cosine of radians) 0.018 -0.017 0.054
fixed temperature 0.031 -0.008 0.07
fixed Google Mobility -0.084 -0.199 0.038
random site (Intercept) 11% 9% 12%
random country (Intercept) 0% -1% 2%
random Google Mobility (slope) | country 0% -1% 2%
random Residual 89% 84% 93%
03a 3399 fixed (Intercept) -0.02 -0.174 0.128
fixed year 0.027 -0.018 0.072
fixed starting distance (ln) 0.487 0.453 0.52
fixed flock size (ln) 0.002 -0.025 0.03
fixed body mass (ln) 0.026 -0.06 0.11
fixed time (sine of radians) 0.001 -0.041 0.042
fixed time (cosine of radians) 0.008 -0.028 0.043
fixed temperature 0.022 -0.018 0.061
fixed Google Mobility -0.108 -0.232 0.015
random species within day & year (Intercept) 6% 5% 6%
random species within site (Intercept) 4% 4% 5%
random site (Intercept) 9% 8% 9%
random species (Intercept) 7% 6% 9%
random genus (Intercept) 3% 3% 4%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 0% -5% 4%
random Google Mobility (slope) | country 0% -5% 4%
random Residual 70% 60% 81%
03b 3399 fixed (Intercept) -0.011 -0.136 0.111
fixed year 0.031 -0.011 0.072
fixed starting distance (ln) 0.487 0.454 0.52
fixed flock size (ln) 0.002 -0.023 0.029
fixed body mass (ln) 0.037 -0.046 0.119
fixed time (sine of radians) -0.002 -0.044 0.04
fixed time (cosine of radians) 0.008 -0.027 0.042
fixed temperature 0.024 -0.017 0.063
fixed Google Mobility -0.126 -0.256 0.009
random species within day & year (Intercept) 6% 5% 6%
random species within site (Intercept) 4% 4% 5%
random site (Intercept) 9% 9% 9%
random species (Intercept) 8% 7% 9%
random genus (Intercept) 0% -1% 4%
random Google Mobility (slope) | genus 0% -1% 4%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 1% -2% 3%
random Google Mobility (slope) | country 1% -2% 3%
random Residual 69% 58% 79%
03c 3399 fixed (Intercept) -0.068 -0.156 0.023
fixed year 0.022 -0.019 0.063
fixed starting distance (ln) 0.549 0.517 0.583
fixed flock size (ln) -0.019 -0.047 0.008
fixed body mass (ln) -0.019 -0.049 0.011
fixed time (sine of radians) -0.024 -0.066 0.019
fixed time (cosine of radians) 0.015 -0.021 0.052
fixed temperature 0.029 -0.01 0.069
fixed Google Mobility -0.091 -0.205 0.022
random site (Intercept) 11% 10% 13%
random country (Intercept) 0% 0% 2%
random Google Mobility (slope) | country 0% 0% 2%
random Residual 88% 83% 91%

Note that (1a) model is the one reported in the Fig. S6.

Table S2d | Alternative models on escape distance given # of humans

    # humans
     mh01a_ = m_out(name = "Table S2d - 1a", dep = "Escape distance", model = mh01a, nsim = 5000)
     mh01b_ = m_out(name = "Table S2d - 1b", dep = "Escape distance", model = mh01b, nsim = 5000)
     mh01c_ = m_out(name = "Table S2d - 1c", dep = "Escape distance", model = mh01c, nsim = 5000)

     mh02a_ = m_out(name = "Table S2d - 2a", dep = "Escape distance", model = mh02a, nsim = 5000)
     mh02b_ = m_out(name = "Table S2d - 2b", dep = "Escape distance", model = mh02b, nsim = 5000)
     mh02c_ = m_out(name = "Table S2d - 2c", dep = "Escape distance", model = mh02c, nsim = 5000)

     mh03a_ = m_out(name = "Table S2d - 3a", dep = "Escape distance", model = mh03a, nsim = 5000)
     mh03b_ = m_out(name = "Table S2d - 3b", dep = "Escape distance", model = mh03b, nsim = 5000)
     mh03c_ = m_out(name = "Table S2d - 3c", dep = "Escape distancey", model = mh03c, nsim = 5000)

     out4 = rbind(mh01a_, mh01b_, mh01c_, mh02a_, mh02b_, mh02c_, mh03a_, mh03b_, mh03c_, fill = TRUE)
     out4[is.na(out4)] = ""
      out4[, effect := gsub("scale\\(Human\\)", "# of humans", effect)]
      out4[, effect := gsub("scale\\(Year\\)", "year", effect)]
      out4[, effect := gsub("scale\\(log\\(SD\\)\\)", "starting distance (ln)", effect)]
      out4[, effect := gsub("scale\\(Temp\\)", "temperature", effect)]
      out4[, effect := gsub("scale\\(log\\(FlockSize\\)\\)", "flock size (ln)", effect)]
      out4[, effect := gsub("scale\\(log\\(BodyMass\\)\\)", "body mass (ln)", effect)]
      out4[, effect := gsub("scale\\(sin\\(rad\\)\\)", "time (sine of radians)", effect)]
      out4[, effect := gsub("scale\\(cos\\(rad\\)\\)", "time (cosine of radians)", effect)]
       out4[, effect := gsub("Species", "species", effect)]
       out4[, effect := gsub("Country", "country", effect)]
       out4[, effect := gsub("Year", "year", effect)]
       out4[, effect := gsub("sp_day_year", "species within day & year", effect)]
       out4[, effect := gsub("IDLocality", "site", effect)]
       out4[, effect := gsub("sp_loc", "species within site", effect)]
       out4[type == "random" & grepl("# of humans", effect, fixed = TRUE), effect := paste("# of humans (slope) |", gsub(" # of humans", "", effect))]
       out4$R2_mar = out4$R2_con = NULL
     fwrite(file = here::here("Outputs/Table_S2d.csv"), out4)
     out4$response = out4$error_structure = NULL
     out4[model != "", model := paste0("0", substring(model, 13))]
     setnames(out4, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
     out4 %>%
          kbl() %>%
          kable_paper("hover", full_width = F)
model N type effect estimate lower upper
01a 3504 fixed (Intercept) 0.243 0.013 0.47
fixed starting distance (ln) 0.463 0.429 0.498
fixed flock size (ln) -0.021 -0.048 0.005
fixed body mass (ln) 0.148 0.039 0.258
fixed time (sine of radians) 0.02 -0.015 0.056
fixed time (cosine of radians) -0.009 -0.04 0.023
fixed temperature -0.024 -0.063 0.012
fixed # of humans -0.055 -0.104 -0.006
random species within day & year (Intercept) 7% 7% 8%
random species within site (Intercept) 2% 2% 3%
random site (Intercept) 7% 6% 8%
random species (Intercept) 4% 3% 5%
random genus (Intercept) 14% 10% 17%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 0% 0% 0%
random # of humans (slope) | country 0% 0% 0%
random year (Intercept) 5% 3% 6%
random Residual 60% 55% 66%
01b 3504 fixed (Intercept) 0.108 -0.165 0.386
fixed starting distance (ln) 0.469 0.434 0.503
fixed flock size (ln) -0.023 -0.048 0.004
fixed body mass (ln) 0.084 -0.002 0.172
fixed time (sine of radians) 0.016 -0.019 0.052
fixed time (cosine of radians) 0.004 -0.029 0.033
fixed temperature -0.02 -0.055 0.014
fixed # of humans -0.056 -0.117 0.005
random # of humans (slope) | species within day & year 0% 0% 0%
random species within site (Intercept) 6% 5% 6%
random site (Intercept) 7% 6% 6%
random species (Intercept) 14% 13% 14%
random # of humans (slope) | genus 0% 0% 0%
random weekday (Intercept) 0% 0% 1%
random country (Intercept) 0% -1% 7%
random # of humans (slope) | country 0% -1% 7%
random year (Intercept) 5% 3% 5%
random Residual 68% 54% 75%
01c 3504 fixed (Intercept) 0.176 -0.143 0.508
fixed starting distance (ln) 0.47 0.435 0.504
fixed flock size (ln) -0.028 -0.054 -0.002
fixed body mass (ln) 0.211 0.097 0.323
fixed time (sine of radians) 0.024 -0.014 0.062
fixed time (cosine of radians) -0.011 -0.044 0.022
fixed temperature -0.026 -0.063 0.012
fixed # of humans -0.054 -0.109 0.003
random species within day & year (Intercept) 8% 6% 9%
random species within site (Intercept) 4% 3% 4%
random site (Intercept) 6% 5% 5%
random genus (Intercept) 19% 16% 18%
random country (Intercept) 0% -2% 9%
random # of humans (slope) | country 0% -2% 9%
random year (Intercept) 5% 4% 5%
random Residual 58% 43% 67%
02a 3446 fixed (Intercept) 0.108 -0.113 0.326
fixed starting distance (ln) 0.461 0.427 0.495
fixed flock size (ln) -0.019 -0.045 0.008
fixed body mass (ln) 0.01 -0.09 0.111
fixed time (sine of radians) 0.017 -0.02 0.054
fixed time (cosine of radians) -0.009 -0.042 0.024
fixed temperature -0.027 -0.065 0.012
fixed # of humans -0.055 -0.106 -0.005
random species within day & year (Intercept) 8% 8% 9%
random species within site (Intercept) 2% 2% 2%
random site (Intercept) 8% 7% 8%
random species (Intercept) 5% 4% 6%
random genus (Intercept) 6% 4% 8%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 0% 0% 0%
random # of humans (slope) | country 0% 0% 0%
random year (Intercept) 5% 4% 7%
random Residual 65% 60% 71%
02b 3446 fixed (Intercept) 0.004 -0.337 0.36
fixed starting distance (ln) 0.464 0.429 0.498
fixed flock size (ln) -0.02 -0.046 0.007
fixed body mass (ln) 0.009 -0.095 0.113
fixed time (sine of radians) 0.02 -0.018 0.059
fixed time (cosine of radians) -0.009 -0.042 0.024
fixed temperature -0.029 -0.065 0.009
fixed # of humans -0.054 -0.108 0
random species within day & year (Intercept) 9% 6% 10%
random species within site (Intercept) 3% 2% 3%
random site (Intercept) 6% 4% 5%
random species (Intercept) 5% 4% 4%
random genus (Intercept) 0% 0% 5%
random # of humans (slope) | genus 0% 0% 5%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 0% -3% 13%
random # of humans (slope) | country 0% -3% 13%
random year (Intercept) 6% 4% 5%
random Residual 71% 43% 79%
02c 3446 fixed (Intercept) 0.069 -0.263 0.401
fixed starting distance (ln) 0.469 0.434 0.503
fixed flock size (ln) -0.028 -0.054 -0.002
fixed body mass (ln) 0.094 -0.011 0.198
fixed time (sine of radians) 0.022 -0.016 0.061
fixed time (cosine of radians) -0.013 -0.045 0.021
fixed temperature -0.029 -0.067 0.009
fixed # of humans -0.052 -0.111 0.006
random species within day & year (Intercept) 9% 7% 10%
random species within site (Intercept) 5% 3% 5%
random site (Intercept) 6% 5% 5%
random genus (Intercept) 11% 9% 10%
random country (Intercept) 0% -3% 12%
random # of humans (slope) | country 0% -3% 12%
random year (Intercept) 6% 4% 6%
random Residual 64% 45% 73%
03a 3408 fixed (Intercept) -0.005 -0.357 0.34
fixed starting distance (ln) 0.458 0.423 0.491
fixed flock size (ln) -0.02 -0.046 0.007
fixed body mass (ln) 0.022 -0.087 0.134
fixed time (sine of radians) 0.02 -0.018 0.058
fixed time (cosine of radians) -0.009 -0.041 0.025
fixed temperature -0.028 -0.066 0.011
fixed # of humans -0.051 -0.108 0.008
random species within day & year (Intercept) 9% 6% 9%
random species within site (Intercept) 2% 2% 3%
random site (Intercept) 5% 4% 5%
random species (Intercept) 5% 4% 5%
random genus (Intercept) 6% 4% 6%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 0% -3% 13%
random # of humans (slope) | country 0% -3% 13%
random year (Intercept) 5% 4% 5%
random Residual 66% 44% 76%
03b 3408 fixed (Intercept) -0.005 -0.362 0.348
fixed starting distance (ln) 0.458 0.424 0.493
fixed flock size (ln) -0.02 -0.046 0.007
fixed body mass (ln) 0.022 -0.088 0.129
fixed time (sine of radians) 0.02 -0.019 0.06
fixed time (cosine of radians) -0.008 -0.041 0.025
fixed temperature -0.028 -0.066 0.011
fixed # of humans -0.054 -0.111 0.001
random species within day & year (Intercept) 9% 6% 10%
random species within site (Intercept) 3% 2% 3%
random site (Intercept) 6% 4% 5%
random species (Intercept) 6% 4% 5%
random genus (Intercept) 0% 0% 5%
random # of humans (slope) | genus 0% 0% 5%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 0% -3% 13%
random # of humans (slope) | country 0% -3% 13%
random year (Intercept) 6% 4% 5%
random Residual 71% 43% 80%
03c 3408 fixed (Intercept) 0.057 -0.285 0.412
fixed starting distance (ln) 0.463 0.427 0.498
fixed flock size (ln) -0.029 -0.054 -0.001
fixed body mass (ln) 0.108 -0.001 0.219
fixed time (sine of radians) 0.022 -0.019 0.061
fixed time (cosine of radians) -0.012 -0.044 0.021
fixed temperature -0.028 -0.067 0.009
fixed # of humans -0.052 -0.115 0.007
random species within day & year (Intercept) 9% 7% 10%
random species within site (Intercept) 5% 3% 5%
random site (Intercept) 6% 5% 5%
random genus (Intercept) 12% 10% 11%
random country (Intercept) 0% -3% 12%
random # of humans (slope) | country 0% -3% 12%
random year (Intercept) 6% 4% 6%
random Residual 64% 45% 72%

Note that (1a) model is the one reported in the Fig. S6.


Correlations among predictors

d[, sin_rad := sin(rad)]
d[, cos_rad := cos(rad)]

dp <- d[, c("Covid", "StringencyIndex", "parks_percent_change_from_baseline", "Human", "SD_ln", "flock_ln", "body_ln", "sin_rad", "cos_rad", "Temp", "Day")]
setnames(dp, old = c("Covid", "StringencyIndex", "parks_percent_change_from_baseline", "Human", "SD_ln", "flock_ln", "body_ln", "sin_rad", "cos_rad", "Temp", "Day"), new = c("Period", "Stringency Index", "Google Mobility", "# of humans", "Starting distance\nln(m)", "Flock size\nln()", "Body mass\nln(g)", "Sine\nof radians", "Cosine\nof radians", "Temperature\n°C", "Day"))

# dp <- d[, c("SD_ln", "flock_ln", "body_ln", "sin_rad", "cos_rad", "Temp", "Day")]
# setnames(dp, old = c("SD_ln", "flock_ln", "body_ln", "sin_rad", "cos_rad", "Temp", "Day"), new = c("Starting distance\nln(m)", "Flock size\nln(m)", "Body mass\nln(m)", "Sine\nof radians", "Cosine\nof radians", "Temperature\n°C", "Day"))

#if (save_plot == TRUE) {
#  png(here::here("Outputs/Fig_S1_rev.png"), width = 19, height = 19, units = "cm", bg = "transparent", res = 600)
#  chart.Correlation(dp, histogram = TRUE, pch = 19, alpha = 0.5)
#  mtext("Single observations", side = 3, line = 3)
#  dev.off()
#}
chart.Correlation(dp, histogram = TRUE, pch = 19, alpha = 0.5)
mtext("Single observations", side = 3, line = 3)

Figure S2 | Pairwise correlations among predictors of escape distance used in this study. On the diagonal: histograms and density lines (red) for each variable. Above diagonal: Pearson’s correlation with stars indicating significance . Below diagonal: the bivariate scatterplots, with each dot representing a single observation and a red line representing smoothed fit. Note that first four predictors were never entered togetheer in a single model with escape distance as dependent variable. Created with chart.Correlation function from R-package PerformanceAnalytics (Peterson & Carl 2020).


Species-site specific distributions

pxx = pp[N_during > 4 & N_before > 4]
dxx = d[paste(IDLocality, Species) %in% paste(pxx$IDLocality, pxx$Species)]
# table(dxx$IDLocality, dxx$Year)
#length(unique(pxx$IDLocality))
#length(unique(pxx$Species))
#sum(pxx$N_during) + sum(pxx$N_before)

dxx[, Country := factor(Country, levels = rev(c("Finland", "Poland", "Czechia", "Hungary", "Australia")))]
dxx[, sp_C_loc2 := paste(gsub("[_]", " ", Species), Country, IDLocality, sep = "\n")]
dxx[, genus := sub("_.*", "", Species)]
dxx[Covid == 0, period := "before COVID-19"]
dxx[Covid == 1, period := "during COVID-19"]

col3_ <- c("#357EBDFF", "#D43F3AFF", "#46B8DAFF", "#5CB85CFF", "#EEA236FF", "#9632B8FF", "#9632B8FF")[7:1]
col3__ <- col3_[3:7]

g_f2 = 
ggplot(dxx, aes(x = as.factor(Year), y = FID, col = Country)) +
  geom_boxplot(outlier.size = 0.5) +
  #geom_rect(data=NULL, aes(xmin = 3.5, xmax = Inf, ymin = -Inf, ymax = Inf), color = "grey60", fill = "grey60")+
  scale_y_continuous("Flight initiation distance [m]", trans = "log10") +
  annotate(geom = "rect",
             xmin = 3.5,
             xmax = +Inf,
             ymin = 1,
             ymax = +Inf,
             color = "grey95", fill = "grey95") +
  geom_boxplot(outlier.size = 0.5) +
  facet_wrap(~sp_C_loc2) +
  
  scale_x_discrete("Year", guide = guide_axis(angle = 45)) +
  # scale_color_continuous() +
  scale_colour_manual(values = col3__, guide = guide_legend(reverse = TRUE)) +
  #scale_fill_manual(values = c("white", "lightgrey")) +
  theme_MB +
  theme(
    plot.title = element_text(size = 7),
    strip.background = element_blank(),
    strip.text.x = element_text(size = 5, color = "grey30", margin = margin(1, 1, 1, 1, "mm")),
    # panel.spacing = unit(1, "mm"),
    legend.position = "none", # c(1, 0.01),
    legend.justification = c(1, 0),
    legend.title = element_blank(),
    # legend.spacing.y = unit(-0.78, "cm")
    # legend.spacing.y = unit(0.02, "cm") use if LOESS smooth text as legend
    legend.spacing.y = unit(-0.9, "cm"),
    axis.text.x = element_text(colour = "grey30", size = 6),
    axis.text.y = element_text(colour = "grey30", size = 6)
  )
if (save_plot == TRUE) {
  ggsave(here::here("Outputs/Fig_2_rev_v3.png"), g_f2, width = 18, height = 16, units = "cm")
}

g_f2

Figure 2 | Temporal variation in avian tolerance toward humans across species. Each heading denotes the scientific name of the species, country and unique site ID within each country. Boxplots outline colour highlights country (as in Fig. 1), background colour indicates Period (white: before the COVID-19 shutdowns; grey: during the COVID-19 shutdowns). Boxplots depict median (horizontal line inside the box), the 25th and 75th percentiles (box) ± 1.5 times the interquartile range or the minimum/maximum value, whichever is smaller (bars), and the outliers (dots). Included are only species–site combinations with ≥5 observations per Period. Y-axis is on the log-scale. Note the lack of consistent shutdowns effects within and between species as well as within and between the countries.


Between/within-genus variation

# prepare data for fig 3 & s3
dxx <- d[paste(IDLocality, Species) %in% paste(pp$IDLocality, pp$Species)]
# length(dxx[, unique(paste(sp_loc, Covid))])
m <- lm(log(FID) ~ log(SD), dxx)
dxx[, resid_FID := resid(m)]
a <- dxx[, .(mean(resid_FID), sd(resid_FID), mean(FID), .N), by = .(Country, IDLocality, genus, Species, sp_loc, Covid)]
setnames(a, old = c("V1", "V2", "V3"), new = c("resid_FID_avg", "SD", "FID_avg"))
a[is.na(SD), SD := 0]

aw <- reshape(a, idvar = c("Country", "IDLocality", "genus", "Species", "sp_loc"), timevar = "Covid", direction = "wide")
aw[, Species := gsub("[_]", " ", Species)]
aw <- merge(aw, t, all.x = TRUE)
# table(aw$Family)

x <- aw[, .N, by = Species]
# x[order(Species)]
aw[, genus2 := genus]
aw[Species %in% x[N %in% c(1, 2), Species], genus2 := "other"]

# aw[genus2 == "Phoenicurus", unique(Species)]

ph[genus2 == "Motacilla" | uid %in% c("67a9ecfd-58ba-44a4-9986-243b6e610419"), uid := "cf522e02-35cc-44f5-841c-0e642987c2e4"]
ph[genus2 == "Sylvia", uid := "67a9ecfd-58ba-44a4-9986-243b6e610419"]

ph[, size := 0.2]
ph[genus2 %in% c("Anas", "Columba", "Dendrocopos", "Sturnus"), size := c(0.25, 0.25, 0.15, 0.1)]
ph[, FID_avg.0 := 1.5]
ph[, FID_avg.1 := 20]
ph[genus2 %in% c("Anas", "Columba"), FID_avg.0 := c(1.7, 1.7)]

ph[, resid_FID_avg.0 := -1.7]
ph[, resid_FID_avg.1 := 0.7]
ph[genus2 %in% c("Anas", "Columba"), resid_FID_avg.0 := c(-1.6, -1.6)]

ph[, genus2 := factor(genus2, levels = c("Anas", "Larus", "Columba", "Dendrocopos", "Picus", "Motacilla", "Erithacus", "Phoenicurus", "Turdus", "Sylvia", "Parus", "Sitta", "Pica", "Garrulus", "Corvus", "Sturnus", "Passer", "Fringilla", "other"))]

aw[, genus2 := factor(genus2, levels = c("Anas", "Larus", "Columba", "Dendrocopos", "Picus", "Motacilla", "Erithacus", "Phoenicurus", "Turdus", "Sylvia", "Parus", "Sitta", "Pica", "Garrulus", "Corvus", "Sturnus", "Passer", "Fringilla", "other"))]

aw[, genus2 := factor(genus2, levels = c("Anas", "Larus", "Columba", "Dendrocopos", "Picus", "Motacilla", "Erithacus", "Phoenicurus", "Turdus", "Sylvia", "Parus", "Sitta", "Pica", "Garrulus", "Corvus", "Sturnus", "Passer", "Fringilla", "other"))]

# Fig 3 and left panel of S3- plot from files
anas <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Anas.png"))))
columba <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Columba.png"))))
Dendrocopos <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Dendrocopos.png"))))
Larus <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Larus_flip.png"))))
Picus <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Picus.png"))))
Motacilla <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Motacilla.png"))))
Erithacus <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Erithacus.png"))))
Phoenicurus <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Phoenicurus.png"))))
Turdus <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Turdus.png"))))
Sylvia <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Sylvia.png"))))
Parus <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Parus_flip.png"))))
Sitta <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Sitta.png"))))
Pica <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Pica.png"))))
Garrulus <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Garrulus.png"))))
Corvus <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Corvus.png"))))
Sturnus <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Sturnus.png"))))
Passer <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Passer_flip.png"))))
Fringilla <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/Fringilla.png"))))
other <- rasterGrob(change_col("#CCCCCC", readPNG(here::here("Data/Pics/other_flip.png"))))

ann_text <- data.frame(
  FID_avg.0 = 8, FID_avg.1 = 10, lab = "Text",
  genus2 = factor("Anas", levels = c("Anas", "Larus", "Columba", "Dendrocopos", "Picus", "Motacilla", "Erithacus", "Phoenicurus", "Turdus", "Sylvia", "Parus", "Sitta", "Pica", "Garrulus", "Corvus", "Sturnus", "Passer", "Fringilla", "other"))
)
ann_text2 <- data.frame(
  FID_avg.0 = 6, FID_avg.1 = 3, lab = "Text",
  genus2 = factor("Larus", levels = c("Anas", "Larus", "Columba", "Dendrocopos", "Picus", "Motacilla", "Erithacus", "Phoenicurus", "Turdus", "Sylvia", "Parus", "Sitta", "Pica", "Garrulus", "Corvus", "Sturnus", "Passer", "Fringilla", "other"))
)

aw2 <- data.frame(FID_avg.0 = c(11.25, 11.25), FID_avg.1 = c(3.5, 5.8), genus2 = factor("Larus", levels = c("Anas", "Larus", "Columba", "Dendrocopos", "Picus", "Motacilla", "Erithacus", "Phoenicurus", "Turdus", "Sylvia", "Parus", "Sitta", "Pica", "Garrulus", "Corvus", "Sturnus", "Passer", "Fringilla", "other")))

col3_ <- c("#357EBDFF", "#D43F3AFF", "#46B8DAFF", "#5CB85CFF", "#EEA236FF", "#9632B8FF", "#9632B8FF")[7:1]
col3__ <- col3_[3:7]

aw[, Country := factor(Country, levels = rev(c("Finland", "Poland", "Czechia", "Hungary", "Australia")))]
g_gen <-
  ggplot(aw, aes(x = FID_avg.0, y = FID_avg.1)) +
  # geom_errorbar(aes(ymin = FID_avg.1-SD.1, ymax = FID_avg.1+SD.1, col = Country), width = 0) +
  # geom_errorbar(aes(xmin = FID_avg.0-SD.0, xmax = FID_avg.0+SD.0, col = Country), width = 0) +
  # geom_point(pch = 21, alpha = 0.7, aes(col = Country)) +
  annotation_custom2(anas, data = ph[genus2 == "Anas"], xmin = 0.05, xmax = 0.5, ymax = 2.6) +
  annotation_custom2(Larus, data = ph[genus2 == "Larus"], xmin = 0.05, xmax = 0.5, ymax = 2.6) +
  annotation_custom2(columba, data = ph[genus2 == "Columba"], xmin = 0.05, xmax = 0.4, ymax = 2.7) +
  annotation_custom2(Dendrocopos, data = ph[genus2 == "Dendrocopos"], xmin = 0.05, xmax = 0.25, ymax = 2.6) +
  annotation_custom2(Picus, data = ph[genus2 == "Picus"], xmin = 0.05, xmax = 0.4, ymax = 2.7) +
  annotation_custom2(Motacilla, data = ph[genus2 == "Motacilla"], xmin = 0.05, xmax = 0.5, ymax = 2.7) +
  annotation_custom2(Erithacus, data = ph[genus2 == "Erithacus"], xmin = 0.05, xmax = 0.35, ymax = 2.7) +
  annotation_custom2(Phoenicurus, data = ph[genus2 == "Phoenicurus"], xmin = 0.05, xmax = 0.35, ymax = 2.7) +
  annotation_custom2(Turdus, data = ph[genus2 == "Turdus"], xmin = 0.05, xmax = 0.5, ymax = 2.7) +
  annotation_custom2(Sylvia, data = ph[genus2 == "Sylvia"], xmin = 0.05, xmax = 0.5, ymax = 2.7) +
  annotation_custom2(Parus, data = ph[genus2 == "Parus"], xmin = 0.05, xmax = 0.42, ymax = 2.7) +
  annotation_custom2(Sitta, data = ph[genus2 == "Sitta"], xmin = 0.05, xmax = 0.5, ymax = 2.7) +
  annotation_custom2(Pica, data = ph[genus2 == "Pica"], xmin = 0.05, xmax = 0.5, ymax = 2.5) +
  annotation_custom2(Garrulus, data = ph[genus2 == "Garrulus"], xmin = 0.05, xmax = 0.6, ymax = 2.7) +
  annotation_custom2(Corvus, data = ph[genus2 == "Corvus"], xmin = 0.05, xmax = 0.4, ymax = 2.55) +
  annotation_custom2(Sturnus, data = ph[genus2 == "Sturnus"], xmin = 0.05, xmax = 0.24, ymax = 2.65) +
  annotation_custom2(Passer, data = ph[genus2 == "Passer"], xmin = 0.05, xmax = 0.36, ymax = 2.65) +
  annotation_custom2(Fringilla, data = ph[genus2 == "Fringilla"], xmin = 0.05, xmax = 0.5, ymax = 2.7) +
  annotation_custom2(other, data = ph[genus2 == "other"], xmin = 0.05, xmax = 0.45, ymax = 2.4) +
  geom_point(pch = 21, alpha = 0.7, aes(fill = Country), col = "grey20", alpha = 0.8) + # col = "white") +
  # ggtitle ("Sim based")+
  geom_abline(intercept = 0, slope = 1, lty = 3, col = "grey80") +
  geom_line(data = aw2, col = "grey80", lwd = 0.25) +
  geom_text(data = ann_text, label = "No difference", col = "grey80", angle = 45, size = 2) +
  geom_text(data = ann_text2, label = "Species mean / site", col = "grey60", size = 2, ) +
  facet_wrap(~genus2) +
  # geom_phylopic(data = o, aes(image = uid),  color = "grey80", size = o$size) + # ,
  # scale_fill_viridis(discrete = TRUE, guide = guide_legend(reverse = FALSE)) +
  scale_fill_manual(values = col3__, guide = guide_legend(reverse = TRUE)) +
  scale_x_continuous("Before COVID-19 shutdown - flight initiation distance [m]", expand = c(0, 0), trans = "log10") +
  scale_y_continuous("During COVID-19 shutdown - flight initiation distance [m]", expand = c(0, 0), trans = "log10") +
  # labs(title = "Species means per sampling location")+
  theme_MB +
  theme(
    plot.title = element_text(size = 7),
    strip.background = element_blank(),
    # panel.spacing = unit(1, "mm"),
    legend.position = c(1, 0.025),
    legend.justification = c(1, -0.05)
  )
gg_gen <- ggplotGrob(g_gen) # gg$layout$name
ggx_gen <- gtable_filter_remove(gg_gen,
  name = paste0("axis-b-", c(2, 4), "-4"),
  trim = FALSE
)
if (save_plot == TRUE) {
  ggsave(here::here("Outputs/Fig_3_width-122mm_col_grey_rev.png"), ggx_gen, width = 4.8, height = 4.5, dpi = 600) # 12.2cm # with label inside
}
grid.draw(ggx_gen)

Figure 3 | Avian tolerance towards humans before and during the COVID-19 shutdowns according to genera. Dots represent means or single escape distance observations of species at specific sites (e.g. park or cemetery) with data for both periods (before and during the shutdowns) and not corrected for other factors such as starting distance of the observer (plot corrected for starting distance gives similar patterns: Fig. S3). Dot colour highlights the country. Dotted lines indicate no difference; dots above the lines indicate lower tolerance towards humans (i.e. longer escape distances), dots below the lines indicate higher tolerance during than before the COVID-19 shutdowns. Panels are ordered according to evolutionary history of birds with top left panels representing the oldest genera, and bottom right, the youngest. Panel titled ‘other’ contains genera with only one or two data points. The axes are on the log-scale. For a species-specific figure, see Fig. S4. Silhouette of Garrulus glandarius, Motacilla alba, Picus viridis, Phoenicurus ochruros, Sylvia borin were drawn by Martin Bulla, Erithacus rubecula drawn by Rebecca Groom, and Fringilla coelebs and Sturnus vulgaris by Maxime Dahirel and all are available at PhyloPic under Creative Commons Attribution 3.0 Unported licence. The remaining silhouettes are available at PhyloPic under the Public Domain Dedication 1.0 license.

# Fig S3 right panel
g_2 <-
  ggplot(aw, aes(x = resid_FID_avg.0, y = resid_FID_avg.1)) +
  geom_point(pch = 21, alpha = 0.7, aes(fill = Country), col = "grey20", alpha = 0.8) + # col = "white") +
  geom_abline(intercept = 0, slope = 1, lty = 3, col = "grey80") +
  facet_wrap(~genus2) +
  # geom_phylopic(data = o, aes(image = uid),  color = "grey80", size = o$size) +
  # scale_fill_viridis(discrete = TRUE, guide = guide_legend(reverse = TRUE)) +
  scale_fill_manual(values = col3__, guide = guide_legend(reverse = TRUE)) +
  scale_x_continuous("Before COVID-19 shutdown - residual escape distance", expand = c(0, 0)) +
  scale_y_continuous("During COVID-19 shutdown - residual escape distance", expand = c(0, 0)) +
  # labs(title = "Species means per sampling location")+
  theme_MB +
  theme(
    plot.title = element_text(size = 7),
    strip.background = element_blank(),
    legend.position = "none",
    # legend.position = c(1, 0),
    legend.justification = c(1, 0)
  )

g_g2 <- ggplotGrob(g_2) # gg$layout$name
g_gx2 <- gtable_filter_remove(g_g2,
  name = paste0("axis-b-", c(2, 4), "-4"),
  trim = FALSE
)
# Fig S5 combine
grid.draw(cbind(ggx_gen, g_gx2, size = "last"))

if (save_plot == TRUE) {
  ggsave(here::here("Outputs/Fig_S3_rev_v3.png"), cbind(ggx_gen, g_gx2, size = "last"), width = 4.8 * 2, height = 4.5, dpi = 600)
}

Figure S3 | Comparison of genus-specific flight initiation distance (left) and residual flight initiation distance (right) before and during the COVID-19 shutdown. Left panel is a copy of a main text Fig. 3 (see there for details). The escape distance represents the raw data that can be confounded by the observers starting distance (for our data the rPearson = 0.58. Right panel dots depict residual escape distances from a model with flight initiation distance (ln-transformed) as a response and starting distance (ln-transformed) as a predictor, i.e. the dots represent before and during shutdowns values that are controlled for starting distance. Note that such control for starting distance (right) has little influence on the depicted relationships. Indeed, the Pearson’s correlation coefficient for escape distance (ln-scale) and residual escape distance was 0.8 for single values and 0.74 for the species means per sampling location.

Difference in number of observations per species and site before and during shutdowns:

ggplot(aw, aes(x = N.0 - N.1)) +
  geom_histogram() + xlab('Before minus during shutdowns\n[# observations]')

# nrow(aw[abs(N.0 - N.1) > 2])
# nrow(aw[!abs(N.0 - N.1) > 2])

Between/within-species variation

aw[, sp2 := gsub(" ", "\n", Species)]
ann_text <- data.frame(
  FID_avg.0 = 8, FID_avg.1 = 10, lab = "Text",
  Species = factor("Aegithalos caudatus", levels = levels(as.factor(aw$Species)))
)
ann_text$sp2 = gsub(" ", "\n", ann_text$Species)
g3 <-
  ggplot(aw, aes(x = FID_avg.0, y = FID_avg.1)) +
  # geom_errorbar(aes(ymin = FID_avg.1-SD.1, ymax = FID_avg.1+SD.1, col = Country), width = 0) +
  # geom_errorbar(aes(xmin = FID_avg.0-SD.0, xmax = FID_avg.0+SD.0, col = Country), width = 0) +
  # geom_point(pch = 21, alpha = 0.7, aes(col = Country)) +
  geom_point(pch = 21, alpha = 0.7, aes(fill = Country), col = "grey20", alpha = 0.8) + # col = "white") +
  # ggtitle ("Sim based")+
  geom_abline(intercept = 0, slope = 1, lty = 3, col = "grey80") +
  geom_text(data = ann_text, label = "No difference", col = "grey80", angle = 45, size = 2) +
  facet_wrap(~sp2) +
  # geom_phylopic(data = o, aes(image = uid),  color = "grey80", size = o$size) + # ,
  # scale_fill_viridis(discrete=TRUE,guide = guide_legend(reverse = FALSE))  +
  scale_fill_manual(values = col3__, guide = guide_legend(reverse = TRUE)) +
  scale_x_continuous("Before COVID-19 shutdown - flight initiation distance [m]", expand = c(0, 0), trans = "log10") +
  scale_y_continuous("During COVID-19 shutdown - flight initiation distance [m]", expand = c(0, 0), trans = "log10") +
  labs(title = "Species means per sampling location") +
  theme_MB +
  theme(
    plot.title = element_text(size = 7),
    strip.background = element_blank(),
    # panel.spacing = unit(1, "mm"),
    legend.position = c(0.96, 0.0),
    legend.justification = c(1, 0)
  )
gg3 <- ggplotGrob(g3) # gg2$layout$name
ggx3 <- gtable_filter_remove(gg3,
  name = c(paste0("axis-b-", c(2, 4), "-7"), "axis-b-6-6"),
  trim = FALSE
)
if (save_plot == TRUE) {
  ggsave(here::here("Outputs/Fig_S4_species_rev_v4.png"), ggx3, width = 13.5, height = 17.5, unit = "cm", dpi = 600) # 11.43cm
}
grid.draw(ggx3)

Figure S4 | Avian tolerance towards humans before and during the COVID-19 shutdowns according to species. Dots represent means or single escape distance observations of species at specific sites (e.g. specific park or cemetery) with data for both periods (i.e. before and during the shutdowns) and not corrected for other factors such as starting distance of the observer. Dot colour highlights the country. Dotted lines indicate no difference, dots above the lines indicate lower tolerance towards humans (i.e. longer escape distances), dots below the lines indicate lower tolerance before than during the COVID-19 shutdowns. Panels are ordered alphabetically. The axes are on the log-scale.


Exploration of human presence

theme_mb2 <-
  theme_MB +
  theme(
    plot.subtitle = element_text(size = 7),
    strip.background = element_blank(),
    strip.text.x = element_text(size = 6, color = "grey30", margin = margin(1, 1, 1, 1, "mm")),
    # panel.spacing = unit(1, "mm"),
    legend.position = "none",
    # legend.spacing.y = unit(-0.78, "cm")
    # legend.spacing.y = unit(0.02, "cm") use if LOESS smooth text as legend
    # legend.spacing.y = unit(-0.9, "cm"),
    axis.text.x = element_text(colour = "grey30", size = 6),
    axis.text.y = element_text(colour = "grey30", size = 6),
    plot.tag = element_text(size = 7)
  )

# Fig_4a - Google Mobility
g_ <- fread(here::here("Data/google_mobility.txt")) # fwrite(d, here::here('Data/data.txt'), sep ='\t')
g_[, Year := as.integer(substring(date, nchar(date) - 3, nchar(date)))]
g_[nchar(date) == 9, date := paste0("0", date)]
g_[, date_ := as.Date(date, format = "%d.%m.%Y")]
g_[, Day := yday(date_)]
setnames(g_, old = "country_region", new = "Country")
g_[, weekday := weekdays(date_)]
g_[, Country := factor(Country, levels = (c("Finland", "Poland", "Czechia", "Hungary", "Australia")))]

ann_text_gg <- data.frame(
  parks_percent_change_from_baseline = 15, Year = 2021, lab = "Text",
  Country = factor("Finland", levels = (c("Finland", "Poland", "Czechia", "Hungary", "Australia")))
)

g0 <- ggplot(g_, aes(x = parks_percent_change_from_baseline, fill = factor(Year))) +
  geom_histogram(position = "dodge", color = NA) +
  facet_wrap(~Country, nrow = 5) +
  # scale_y_continuous(trans = 'log')+
  scale_fill_manual(values = c("orange", "skyblue", "black"), guide = "none") +
  geom_vline(xintercept = 0, lty = 3, col = "#991616") +
  geom_text(data = ann_text_gg, aes(y = 100), label = "Baseline", col = "#991616", size = 1.75, hjust = 0) +
  labs(subtitle = "\nDistributions", x = "Google Mobility\n[% change in human presence]", y = "\n# of days") +
  theme_MB +
  theme(
    plot.subtitle = element_text(size = 7),
    strip.background = element_blank(),
    strip.text.x = element_text(size = 6, color = "grey30", margin = margin(1, 1, 1, 1, "mm")),
    # panel.spacing = unit(1, "mm"),
    legend.position = "none", # c(1, 0.01),
    # legend.spacing.y = unit(-0.78, "cm")
    # legend.spacing.y = unit(0.02, "cm") use if LOESS smooth text as legend
    # legend.spacing.y = unit(-0.9, "cm"),
    axis.text.x = element_text(colour = "grey30", size = 6),
    axis.text.y = element_text(colour = "grey30", size = 6)
  )

g1 <- ggplot(g_, aes(x = Day, y = parks_percent_change_from_baseline, col = factor(Year))) +
  geom_line() +
  facet_wrap(~Country, nrow = 5) +
  # scale_y_continuous(trans = 'log')+
  coord_cartesian(ylim = c(-100, 300)) +
  scale_color_manual(values = c("orange", "skyblue", "black"), guide = "none") +
  labs(subtitle = "\nRaw data", xlab = "Day\n ", y = "Google Mobility\n[% change in human presence]") +
  theme_MB +
  theme(
    plot.subtitle = element_text(size = 7),
    strip.background = element_blank(),
    strip.text.x = element_text(size = 6, color = "grey30", margin = margin(1, 1, 1, 1, "mm")),
    # panel.spacing = unit(1, "mm"),
    legend.position = "none", # c(1, 0.01),
    legend.justification = c(1, 0),
    legend.title = element_blank(),
    # legend.spacing.y = unit(-0.78, "cm")
    # legend.spacing.y = unit(0.02, "cm") use if LOESS smooth text as legend
    legend.spacing.y = unit(-0.9, "cm"),
    axis.text.x = element_text(colour = "grey30", size = 6),
    axis.text.y = element_text(colour = "grey30", size = 6)
  )

g2 <- ggplot(g_, aes(x = Day, y = parks_percent_change_from_baseline, col = factor(Year))) +
  stat_smooth(se = FALSE) +
  facet_wrap(~Country, nrow = 5) +
  # scale_y_continuous(trans = 'log')+
  coord_cartesian(ylim = c(-100, 300)) +
  scale_color_manual(values = c("orange", "skyblue", "black"), labels = c("2020", "2021", "2022 (post-COVID-19)"), name = "Year") +
  labs(subtitle = "Locally estimated\nscatterplot smoothing", xlab = "Day\ntest") +
  theme_MB +
  theme(
    plot.subtitle = element_text(size = 7),
    strip.background = element_blank(),
    strip.text.x = element_text(size = 6, color = "grey30", margin = margin(1, 1, 1, 1, "mm")),
    legend.text = element_text(color = "grey30", size = 6),
    # panel.spacing = unit(1, "mm"),
    # legend.position = "none", # c(1, 0.01),
    legend.justification = c(0, 1),
    legend.box.margin = margin(5, 5, 5, 5),
    # legend.title = element_blank(),
    # legend.spacing.y = unit(-0.78, "cm")
    # legend.spacing.y = unit(0.02, "cm") use if LOESS smooth text as legend
    # legend.background = element_blank(),
    # legend.spacing.y = unit(-0.9, "cm"),
    axis.text.y = element_blank(),
    axis.title.y = element_blank()
  )

g123 <- ggarrange(
  g0, g1, g2,
  ncol = 3, widths = c(0.975, 1, 1.46)
)

fig_4a <- annotate_figure(g123,
  top = textGrob("a)", gp = gpar(cex = 0.7), x = 0.02, vjust = 0, y = 0)
)

# Fig_4b - # of humans distributions before/during
hd1 <-
  ggplot(dh, aes(x = Human, fill = Period)) +
  geom_histogram(position = "dodge", color = NA) +
  labs(subtitle = "All data\n(original-scale)", xlab = "# of humans", ylab = "# of escape distance trials") +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  annotate("text", x = 10, y = 900, label = "Before COVID-19 shutdowns", col = "orange", size = 1.8, hjust = 0) +
  annotate("text", x = 10, y = 800, label = "After COVID-19 shutdowns", col = "skyblue", size = 1.8, hjust = 0) +
  # scale_color_manual(values = c("orange", "skyblue")) +
  scale_fill_manual(values = c("orange", "skyblue"))

hd2 <-
  ggplot(dh, aes(x = Human + 0.01, col = Period, fill = Period)) +
  geom_histogram(position = "dodge", color = NA) +
  scale_x_continuous(
    trans = "log10", expand = c(0, 0),
    breaks = c(0.01, 1, 10, 50),
    labels = c(0, 1, 10, 50)
  ) +
  scale_y_continuous(expand = c(0, 0)) +
  # scale_color_manual(values = c("orange", "skyblue")) +
  scale_fill_manual(values = c("orange", "skyblue")) +
  labs(subtitle = "\n(log-scale)", xlab = "# of humans", ylab = "# of escape distance trials")

hd3 <-
  ggplot(dhh, aes(x = Human, col = Period, fill = Period)) +
  geom_histogram(position = "dodge", color = NA) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  # scale_color_manual(values = c("orange", "skyblue")) +
  scale_fill_manual(values = c("orange", "skyblue")) +
  labs(subtitle = ">0 data\n(original-scale)", xlab = "# of humans", ylab = "# of escape distance trials")

hd4 <-
  ggplot(dhh, aes(x = Human, col = Period, fill = Period)) +
  geom_histogram(position = "dodge", color = NA) +
  scale_x_continuous(trans = "log10", expand = c(0, 0)) +
  # scale_y_continuous(expand = c(0,0)) +
  scale_color_manual(values = c("orange", "skyblue")) +
  scale_fill_manual(values = c("orange", "skyblue")) +
  labs(subtitle = "\n(log-scale)", xlab = "# of humans", ylab = "# of escape distance trials")

hd1234_w <- ggarrange(
  hd1 + theme_mb2 + rremove("ylab") + rremove("xlab"), hd2 + theme_mb2 + rremove("ylab") + rremove("xlab"),
  hd3 + theme_mb2 + rremove("ylab") + rremove("xlab"), hd4 + theme_mb2 + rremove("ylab") + rremove("xlab"),
  ncol = 4, nrow = 1
)

fig_4b <-
  annotate_figure(hd1234_w,
    left = textGrob("# of escape distance trials", rot = 90, gp = gpar(cex = 0.6, col = "grey30"), vjust = 1.2),
    bottom = textGrob("# of humans", gp = gpar(cex = 0.6, col = "grey30"), hjust = 1, vjust = 0),
    top = textGrob("b)", gp = gpar(cex = 0.7), x = -.005, vjust = 0, y = 0)
  )

# Fig_4c - # of humans distributions year & country
dh[, Country := factor(Country, levels = rev(c("Finland", "Poland", "Czechia", "Hungary")))]
dh[, Year_ := factor(Year, levels = rev(c("2018", "2019", "2020", "2021")))]
dh_N <- dh[, .N, by = c("Country", "Year_")]
dh_N[, n_pos := 60]

dhh[, Country := factor(Country, levels = rev(c("Finland", "Poland", "Czechia", "Hungary")))]
dhh[, Year_ := factor(Year, levels = rev(c("2018", "2019", "2020", "2021")))]
dhh_N <- dhh[, .N, by = c("Country", "Year_")]
dhh_N[, n_pos := 75]
width_ <- 1

col_hn <- rev(c("orange", "darkorange3", "skyblue", "deepskyblue4"))

h1 <- ggplot(dh, aes(col = Year_, x = Human, y = Country)) +
  geom_boxplot(position = position_dodge2(width_, preserve = "single"), outlier.size = 0.1) +
  scale_x_continuous(name = "# of humans", lim = c(0, 100)) +
  scale_colour_manual(values = col_hn) +
  guides(col = guide_legend(title = "Year", reverse = TRUE)) +
  labs(subtitle = "All data\n(original scale) ") +
  annotate("text", x = 90, y = 4 + 0.5, label = "Year", col = "grey70", size = 1.8, hjust = 0) +
  annotate("text", x = 90, y = 4 + 0.3, label = "2018", col = "orange", size = 1.8, hjust = 0) +
  annotate("text", x = 90, y = 4 + 0.1, label = "2019", col = "darkorange3", size = 1.8, hjust = 0) +
  annotate("text", x = 90, y = 4 - 0.1, label = "2020", col = "skyblue", size = 1.8, hjust = 0) +
  annotate("text", x = 90, y = 4 - 0.3, label = "2021", col = "deepskyblue4", size = 1.8, hjust = 0) +
  theme_mb2

h2 <- ggplot(dh, aes(col = Year_, x = Human + 0.01, y = Country)) +
  geom_boxplot(position = position_dodge2(width_, preserve = "single"), outlier.size = 0.1) +
  scale_x_continuous(
    trans = "log10", name = "# of humans",
    breaks = c(0.01, 1, 10, 100),
    labels = c(0, 1, 10, 100)
    # ,breaks = trans_breaks("log10", function(x) 10^x),
    # labels = trans_format("log10", math_format(10^.x))
  ) +
  coord_cartesian(xlim = c(0.01, 100)) +
  scale_colour_manual(values = col_hn) +
  guides(col = guide_legend(title = "Year", , reverse = TRUE)) +
  labs(subtitle = "\n(log-scale)") +
  annotate("text", x = 60, y = 4 + 0.5, label = "N", col = "grey70", size = 1.8, hjust = 0) +
  geom_text(data = dh_N, aes(x = n_pos, label = N, y = Country, col = Year_), vjust = 1, hjust = 0, size = 1.8, position = position_dodge2(width_, preserve = "single")) +
  theme_mb2 +
  theme(
    axis.title.y = element_blank(),
    axis.text.y = element_blank()
  )

h3 <- ggplot(dhh, aes(col = Year_, x = Human, y = Country)) +
  geom_boxplot(position = position_dodge2(width_, preserve = "single"), outlier.size = 0.1) +
  coord_cartesian(xlim = c(0, 100)) +
  scale_x_continuous(name = "# of humans") +
  guides(col = guide_legend(title = "Year", reverse = TRUE)) +
  scale_colour_manual(values = col_hn) +
  labs(subtitle = ">0 data\n(original scale)") +
  theme_mb2 +
  theme(
    axis.title.y = element_blank(),
    axis.text.y = element_blank()
  )

h4 <- ggplot(dhh, aes(col = Year_, x = Human, y = Country)) +
  geom_boxplot(position = position_dodge2(width_, preserve = "single"), outlier.size = 0.1) +
  scale_x_continuous(
    trans = "log10", name = "# of humans"
    # ,breaks = trans_breaks("log10", function(x) 10^x),
    # labels = trans_format("log10", math_format(10^.x))
  ) +
  coord_cartesian(xlim = c(1, 100)) +
  scale_colour_manual(values = col_hn) +
  guides(col = guide_legend(title = "Year", reverse = TRUE)) +
  labs(subtitle = "\n(log-scale)") +
  annotate("text", x = 75, y = 4 + 0.5, label = "N", col = "grey70", size = 1.8, hjust = 0) +
  geom_text(data = dhh_N, aes(x = n_pos, label = N, y = Country, col = Year_), vjust = 1, hjust = 0, size = 1.8, position = position_dodge2(width_, preserve = "single")) +
  theme_mb2 +
  theme(
    axis.title.y = element_blank(),
    axis.text.y = element_blank()
  )

h1234 <- ggarrange(
  h1 + rremove("xlab") + rremove("ylab"), h2 + rremove("xlab") + rremove("ylab"),
  h3 + rremove("xlab") + rremove("ylab"), h4 + rremove("xlab") + rremove("ylab"),
  ncol = 4, nrow = 1,
  widths = c(1.35, 1, 1, 1)
)
fig_4c <-
  annotate_figure(h1234,
    bottom = textGrob("# of humans", gp = gpar(cex = 0.6, col = "grey30"), hjust = 1, vjust = 0),
    top = textGrob("c)", gp = gpar(cex = 0.7), x = 0.02, vjust = 0, y = 0)
  )

# combine
fig_4 = ggarrange(fig_4a, fig_4b, fig_4c, nrow = 3, heights = c(11, 5, 6))
if(save_plot==TRUE){
ggsave(here::here("Outputs/Fig_4_width-160mm.png"), fig_4, width = 8 * 2, height = 22, unit = "cm", dpi = 600)
}
fig_4

Figure 4 | Changes in human presence in parks within and between years and countries. (a) The left plots represent distributions (histograms) of human presence (Google Mobility), middle plots the raw data, and right plots locally estimated scatterplot smoothing (Loess). Dotted vertical line in “Distribution” plots indicates baseline value of human presence, separating negative values that indicate decreased human presence and positive values that indicate increased human presence when compared with the baseline. The baseline is country and weekday specific (for weekday-specific patterns, see Fig. S5).Note that Google Mobility data were unavailable for the years before the COVID-19 pandemic (i.e. before 2020) but the year 2022 was without shutdowns in the studied countries. (b-c) Distribution of # of humans at the time of escape distance trial according to Period (before and during COVID-19 shutdowns) (b) and according to year and country of data collection (c; for boxplot definition see Fig. 2). First two panels (in b and c) show all data (N = 3504 observations), last two cases when humans were present (N = 2327); data on original scale (first and third panels) and on log-scale (second and fourth panels. Numbers in (c) indicate sample sizes. Note the lack of COVID-19 shutdown effects on # of humans in parks.

g_w <- fread(here::here("Data/google_mobility.txt")) # fwrite(d, here::here('Data/data.txt'), sep ='\t')
g_w[, Year := as.integer(substring(date, nchar(date) - 3, nchar(date)))]
g_w[nchar(date) == 9, date := paste0("0", date)]
g_w[, date_ := as.Date(date, format = "%d.%m.%Y")]
g_w[, Day := yday(date_)]
setnames(g_w, old = "country_region", new = "Country")
g_w[, weekday := weekdays(date_)]
g_w[, Country := factor(Country, levels = (c("Finland", "Poland", "Czechia", "Hungary", "Australia")))]
g_w[, weekday := factor(weekday, levels = (c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")))]
g_s5 =
ggplot(g_w, aes(x = Day, y = parks_percent_change_from_baseline, col = factor(Year))) +
    geom_line() +
    facet_grid(rows = vars(Country), cols = vars(weekday)) +
    # scale_y_continuous(trans = 'log')+
    scale_color_manual(values = c("orange", "skyblue", "black"))
if(save_plot==TRUE){
ggsave(here::here("Outputs/Fig_S5_rev.png"), g_s5, width = 8 * 2.54, height = 6 * 2.54, unit = "cm", dpi = 600)
}
g_s5

Figure S5 | Changes in human presence (Google Mobility) in parks across weekdays and years. Depicted are raw data connected by lines. Note that Google Mobility data were not freely available for years before the COVID-19 pandemic (i.e. before 2020) but 2022 was a year without shutdowns in the studied countries.


Google Mobility ~ Stringency index

# Predictions 
l = list()
 sscz = ss[Country == "Czechia"]
 cz <- lmer(parks_percent_change_from_baseline ~
    StringencyIndex + 
   (scale(StringencyIndex)|weekday),
 # (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
 data = sscz, REML = FALSE
 )
 bsim <- sim(cz, n.sim = nsim)
 v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
 newD <- data.frame(StringencyIndex = seq(min(sscz$StringencyIndex), max(sscz$StringencyIndex), length.out = 100)) # values to predict for
 X <- model.matrix(~StringencyIndex, data = newD) # exactly the model which was used has to be specified here
 newD$pred <- (X %*% v)
 predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
 for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
 newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
 newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
 newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
 newD$Country = 'Czechia'
 l[[1]] = newD
 
 s[, year_weekday :=paste(Year, weekday)]
 sf = ss[Country == "Finland"]
 fi <- lmer(parks_percent_change_from_baseline ~
    Year+
    StringencyIndex + 
   (scale(StringencyIndex)|year_weekday),
 # (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
 data = sf, REML = FALSE
 )
 bsim <- sim(fi, n.sim = nsim)
 v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
 newD <- data.frame(Year = mean(sf$Year), StringencyIndex = seq(min(sf$StringencyIndex), max(sf$StringencyIndex), length.out = 100)) # values to predict for
 X <- model.matrix(~Year + StringencyIndex, data = newD) # exactly the model which was used has to be specified here
 newD$pred <- (X %*% v)
 predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
 for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
 newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
 newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
 newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
 newD$Country = 'Finland'
 newD$Year = NULL
 l[[2]] = newD

 s_h <- ss[Country == "Hungary"]
 hu <- lmer(parks_percent_change_from_baseline ~
     Year +
     StringencyIndex +
     (scale(StringencyIndex) | year_weekday),
 # (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
 data = s_h, REML = FALSE
 )

 bsim <- sim(hu, n.sim = nsim)
 v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
 newD <- data.frame(Year = mean(s_h$Year), StringencyIndex = seq(min(s_h$StringencyIndex), max(s_h$StringencyIndex), length.out = 100)) # values to predict for
 X <- model.matrix(~ Year + StringencyIndex, data = newD) # exactly the model which was used has to be specified here
 newD$pred <- (X %*% v)
 predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
 for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
 newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
 newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
 newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
 newD$Country <- "Hungary"
 newD$Year <- NULL
 l[[3]] <- newD
 
 sp <- ss[Country == "Poland"]
 pl <- lmer(parks_percent_change_from_baseline ~
     Year +
     StringencyIndex +
     (scale(StringencyIndex) | year_weekday),
 # (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
 data = sp, REML = FALSE
 )
 bsim <- sim(pl, n.sim = nsim)
 v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
 newD <- data.frame(Year = mean(sp$Year), StringencyIndex = seq(min(sp$StringencyIndex), max(sp$StringencyIndex), length.out = 100)) # values to predict for
 X <- model.matrix(~ Year + StringencyIndex, data = newD) # exactly the model which was used has to be specified here
 newD$pred <- (X %*% v)
 predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
 for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
 newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
 newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
 newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
 newD$Country <- "Poland"
 newD$Year <- NULL
 l[[4]] <- newD

 sa <- ss[Country == "Australia"]
 au <- lmer(parks_percent_change_from_baseline ~
     Year +
     StringencyIndex +
     (scale(StringencyIndex) | year_weekday),
 # (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
 data = sa, REML = FALSE
 )

 bsim <- sim(au, n.sim = nsim)
 v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
 newD <- data.frame(Year = mean(sa$Year), StringencyIndex = seq(min(sa$StringencyIndex), max(sa$StringencyIndex), length.out = 100)) # values to predict for
 X <- model.matrix(~ Year + StringencyIndex, data = newD) # exactly the model which was used has to be specified here
 newD$pred <- (X %*% v)
 predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
 for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
 newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
 newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
 newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
 newD$Country <- "Australia"
 newD$Year <- NULL
 l[[5]] <- newD

# Figure G_S
g_s = data.table(do.call(rbind,l))
g_s[, Country := factor(Country, levels = rev(c("Finland", "Poland", "Czechia", "Hungary", "Australia")))]

col3_ = c("#357EBDFF", "#D43F3AFF", "#46B8DAFF", "#5CB85CFF", "#EEA236FF", "#9632B8FF", "#9632B8FF")[7:1]
col3__ = col3_[3:7]
p = 
ggplot(g_s, aes(x = StringencyIndex, y = pred, col = Country)) +
  geom_ribbon(aes(ymin = lwr, ymax = upr, fill = Country, color = NULL), alpha = .15) +
  geom_jitter(aes(y = parks_percent_change_from_baseline, fill = Country), data = s, pch = 21, col = 'grey20', width = 0.7, height = 3, alpha = 0.5) +
  geom_line(lwd = 1) +
  labs(subtitle = "Mixed model per country predicitons", y = "Google Mobiligy\n[% change from baseline]", x = "Stringency Index") +
   # scale_color_locuszoom()+
   # scale_fill_locuszoom(guide = "none")
  scale_x_continuous(breaks = round(seq(25, 75, by = 25), 1)) +
  scale_y_continuous(breaks = round(seq(-100, 200, by = 50), 1)) +
  #scale_y_continuous(breaks = round(seq(-100, 175, by = 25), 1)) +
  scale_colour_manual(values = col3__, guide = guide_legend(reverse = TRUE, override.aes = list(size = 0)), 
            labels = paste("<span style='color:",
                                   col3__,
                                   "'>",
                                   levels(g_s$Country),
                                   "</span>")
            ) +
  scale_fill_manual(values = col3__, guide = "none") +
  theme_bw() +
  theme(
    legend.text = element_markdown(size = 6),
    #legend.position = "right",
    legend.title = element_blank(),
    # legend.spacing.y = unit(0.1, 'cm'),
    legend.key.height = unit(0.5, "line"),
    legend.key.size = unit(0, "line"),
    legend.margin = margin(0, 0, 0, 0),
    legend.box.margin=margin(-10,1,-10,-10),
    # legend.position=c(0.5,1.6),
    plot.title = element_text(color = "grey", size = 7),
    plot.subtitle = element_text(color = "grey60", size = 6),
    plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r = 0.5, unit = "pt"),
    panel.grid = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank(),
    axis.line = element_line(colour = ax_lines, size = 0.25),
    axis.ticks = element_line(colour = ax_lines, size = 0.25),
    # axis.text.x = element_text()
    axis.ticks.length = unit(1, "pt"),
    axis.text = element_text(, size = 6),
    axis.title = element_text(size = 7)
  )

if(save_plot==TRUE){
ggsave(here::here("Outputs/Fig_5_rev_widht_70mm.png"), p + theme(plot.subtitle = element_blank()), width = 7, height = 6, unit = "cm", dpi = 600)
}

p

Figure 5 | Association between human presence in parks (Google Mobility) and stringency of antipandemic governmental restrictions (Stringency index). Lines with shaded areas represent predictions with 95%CIs from country-specific mixed effect models controlled for the year and non-independence of data points by including weekday within the year as random intercept and Stringency index as a random slope (Table S3a). Dots represent raw data, jittered to increase visibility, for days within which we collected escape distances in each city. Colours indicate country. Note the generally negative but weak association between human presence and Stringency index.

Table S3a | Google Mobility in relation to Stringency index

ll = list()

ssf = ss[Country == "Finland"]
fi <- lmer(scale(parks_percent_change_from_baseline) ~
  scale(Year) +
  scale(StringencyIndex) +
  (scale(StringencyIndex) | year_weekday),
data = ssf, REML = FALSE
)
ll[[1]] = m_out(name = "Table S3 - FI", dep = "Google Mobility", model = fi, nsim = 5000)

ssp <- ss[Country == "Poland"]
pl <- lmer(scale(parks_percent_change_from_baseline) ~
  scale(Year) +
  scale(StringencyIndex) +
  (scale(StringencyIndex) | year_weekday),
data = ssp, REML = FALSE
)
ll[[2]] = m_out(name = "Table S3 - PL", dep = "Google Mobility", model = pl, nsim = 5000)

sscz = ss[Country == "Czechia"]
cz <- lmer(scale(parks_percent_change_from_baseline) ~
  scale(StringencyIndex) +
  (scale(StringencyIndex) | weekday),
data = sscz, REML = FALSE
)
ll[[3]] = m_out(name = "Table S3 - CZ", dep = "Google Mobility", model = cz, nsim = 5000)

ss_h <- ss[Country == "Hungary"]
hu <- lmer(scale(parks_percent_change_from_baseline) ~
  scale(Year) +
  scale(StringencyIndex) +
  (scale(StringencyIndex) | year_weekday),
data = ss_h, REML = FALSE
)
ll[[4]] = m_out(name = "Table S3 - HU", dep = "Google Mobility", model = hu, nsim = 5000)

ssa <- ss[Country == "Australia"]
au <- lmer(scale(parks_percent_change_from_baseline) ~
  scale(Year) +
  scale(StringencyIndex) +
  (scale(StringencyIndex) | year_weekday),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = ssa, REML = FALSE
)
ll[[5]] = m_out(name = "Table S3 - AU", dep = "Google Mobility", model = au, nsim = 5000)

out_g_s = data.table(do.call(rbind, ll))
out_g_s[is.na(out_g_s)] <- ""
out_g_s$R2_mar = out_g_s$R2_con = NULL
out_g_s[, effect := gsub("scale\\(Year\\)", "year", effect)]
out_g_s[, effect := gsub("scale\\(StringencyIndex\\)", "Stringency index", effect)]
out_g_s[, effect := gsub("year_weekday", "weekday within year", effect)]
out_g_s[type == "random" & grepl("Stringency index", effect, fixed = TRUE), effect := paste("Stringency index (slope) |", gsub(" Stringency index", "", effect))]
fwrite(file = here::here("Outputs/Table_S3a_rev.csv"), out_g_s)

out_g_s$error_structure = out_g_s$response = NULL
out_g_s[model!="", model:=c('Finland', 
                              'Poland', 
                              'Czechia', 
                              'Hungary', 
                              'Australia')]
setnames(out_g_s, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
out_g_s %>%
  kbl() %>%
  kable_paper("hover", full_width = F)
model N type effect estimate lower upper
Finland 322 fixed (Intercept) -0.337 -1.138 0.487
fixed year 0.93 0.45 1.428
fixed Stringency index -0.283 -1.049 0.517
random weekday within year (Intercept) -20% 48% 53%
random Stringency index (slope) | weekday within year -20% 48% 53%
random Residual 140% -7% 5%
Poland 329 fixed (Intercept) 0.016 -0.617 0.636
fixed year 0.776 0.015 1.537
fixed Stringency index 0.023 -0.362 0.408
random weekday within year (Intercept) 47% 44% 49%
random Stringency index (slope) | weekday within year 47% 44% 49%
random Residual 6% 2% 13%
Czechia 1054 fixed (Intercept) -0.002 -0.508 0.523
fixed Stringency index -0.221 -0.619 0.189
random weekday (Intercept) 23% -166% 40%
random Stringency index (slope) | weekday 23% -166% 40%
random Residual 54% 21% 433%
Hungary 874 fixed (Intercept) 0.242 -0.262 0.755
fixed year -0.001 -0.454 0.475
fixed Stringency index -1.27 -1.949 -0.578
random weekday within year (Intercept) 48% 24% 49%
random Stringency index (slope) | weekday within year 48% 24% 49%
random Residual 4% 2% 53%
Australia 1065 fixed (Intercept) 0.526 0.007 1.07
fixed year 0.441 0.244 0.642
fixed Stringency index -0.541 -0.848 -0.238
random weekday within year (Intercept) -40% 44% 65%
random Stringency index (slope) | weekday within year -40% 44% 65%
random Residual 180% -30% 13%

Number of humans ~ Stringency index & Google Mobility

sh[, Country := factor(Country, levels = (c("Finland", "Czechia", "Hungary")))]
ssh[, Country := factor(Country, levels = (c("Finland", "Czechia", "Hungary")))]

# predictions for humans ~ stringency
lsh <- list()
shf <- sh[Country == "Finland"]
shfi <- lmer(Human ~
  Year +
  StringencyIndex +
  (scale(StringencyIndex) | year_weekday),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = shf, REML = FALSE
)
bsim <- sim(shfi, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(Year = mean(shf$Year), StringencyIndex = seq(min(shf$StringencyIndex), max(shf$StringencyIndex), length.out = 100)) # values to predict for
X <- model.matrix(~ Year + StringencyIndex, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Finland"
newD$Year <- NULL
lsh[[1]] <- newD

shc <- sh[Country == "Czechia"]
shcz <- lmer(Human ~
  StringencyIndex +
  (scale(StringencyIndex) | weekday),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = shc, REML = FALSE
)
bsim <- sim(shcz, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(StringencyIndex = seq(min(shc$StringencyIndex), max(shc$StringencyIndex), length.out = 100)) # values to predict for
X <- model.matrix(~StringencyIndex, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Czechia"
lsh[[2]] <- newD

sh_h <- sh[Country == "Hungary"]
shhu <- lmer(Human ~
  Year +
  StringencyIndex +
  (scale(StringencyIndex) | year_weekday),
data = sh_h, REML = FALSE
)

bsim <- sim(shhu, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(Year = mean(sh_h$Year), StringencyIndex = seq(min(sh_h$StringencyIndex), max(sh_h$StringencyIndex), length.out = 100)) # values to predict for
X <- model.matrix(~ Year + StringencyIndex, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Hungary"
newD$Year <- NULL
lsh[[3]] <- newD

h_s <- data.table(do.call(rbind, lsh))
h_s[, Country := factor(Country, levels = (c("Finland", "Czechia", "Hungary")))]

# predictions for log(humans+0.01) ~ stringency
lsh_ <- list()

shf <- sh[Country == "Finland"]
shfi_ln <- lmer(log(Human+0.01) ~
  Year +
  StringencyIndex +
  (scale(StringencyIndex) | year_weekday),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = shf, REML = FALSE
)
bsim <- sim(shfi_ln, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(Year = mean(shf$Year), StringencyIndex = seq(min(shf$StringencyIndex), max(shf$StringencyIndex), length.out = 100)) # values to predict for
X <- model.matrix(~ Year + StringencyIndex, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Finland"
newD$Year <- NULL
lsh_[[1]] <- newD

shc <- sh[Country == "Czechia"]
shcz_ln <- lmer(log(Human+0.01) ~
  StringencyIndex +
  (scale(StringencyIndex) | weekday),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = shc, REML = FALSE
)
bsim <- sim(shcz_ln, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(StringencyIndex = seq(min(shc$StringencyIndex), max(shc$StringencyIndex), length.out = 100)) # values to predict for
X <- model.matrix(~StringencyIndex, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Czechia"
lsh_[[2]] <- newD

sh_h <- sh[Country == "Hungary"]
shhu_ln <- lmer(log(Human+0.01) ~
  Year +
  StringencyIndex +
  (scale(StringencyIndex) | year_weekday),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = sh_h, REML = FALSE
)

bsim <- sim(shhu_ln, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(Year = mean(sh_h$Year), StringencyIndex = seq(min(sh_h$StringencyIndex), max(sh_h$StringencyIndex), length.out = 100)) # values to predict for
X <- model.matrix(~ Year + StringencyIndex, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Hungary"
newD$Year <- NULL
lsh_[[3]] <- newD

h_s_ln <- data.table(do.call(rbind, lsh_))
h_s_ln[, Country := factor(Country, levels = (c("Finland", "Czechia", "Hungary")))]
h_s_ln[, pred_o := exp(pred) - 0.01]
h_s_ln[, lwr_o := exp(lwr) - 0.01]
h_s_ln[, upr_o := exp(upr) - 0.01]

# predictions for humans ~ Google
lshg <- list()

sshf <- ssh[Country == "Finland"]
sshfi <- lmer(Human ~
  Year +
  parks_percent_change_from_baseline +
  (scale(parks_percent_change_from_baseline) | year_weekday),
data = sshf, REML = FALSE
)
bsim <- sim(sshfi, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(Year = mean(sshf$Year), parks_percent_change_from_baseline = seq(min(sshf$parks_percent_change_from_baseline), max(sshf$parks_percent_change_from_baseline), length.out = 100)) # values to predict for
X <- model.matrix(~ Year + parks_percent_change_from_baseline, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Finland"
newD$Year <- NULL
lshg[[1]] <- newD

sshc <- ssh[Country == "Czechia"]
sshcz <- lmer(Human ~
  parks_percent_change_from_baseline +
  (scale(parks_percent_change_from_baseline) | weekday),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = sshc, REML = FALSE
)
bsim <- sim(sshcz, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(parks_percent_change_from_baseline = seq(min(sshc$parks_percent_change_from_baseline), max(sshc$parks_percent_change_from_baseline), length.out = 100)) # values to predict for
X <- model.matrix(~parks_percent_change_from_baseline, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Czechia"
lshg[[2]] <- newD

ssh_h <- ssh[Country == "Hungary"]
sshhu <- lmer(Human ~
  Year +
  parks_percent_change_from_baseline +
  ((parks_percent_change_from_baseline) | year_weekday),
data = ssh_h, REML = FALSE
)

bsim <- sim(sshhu, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(Year = mean(ssh_h$Year), parks_percent_change_from_baseline = seq(min(ssh_h$parks_percent_change_from_baseline), max(ssh_h$parks_percent_change_from_baseline), length.out = 100)) # values to predict for
X <- model.matrix(~ Year + parks_percent_change_from_baseline, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Hungary"
newD$Year <- NULL
lshg[[3]] <- newD

h_sg <- data.table(do.call(rbind, lshg))
h_sg[, Country := factor(Country, levels = (c("Finland", "Czechia", "Hungary")))]

# predictions for log(humans+0.01) ~ Google
lshg_ <- list()

sshf <- ssh[Country == "Finland"]
sshfi_ln <- lmer(log(Human+0.01) ~
  Year +
  parks_percent_change_from_baseline +
  (scale(parks_percent_change_from_baseline) | year_weekday),
data = sshf, REML = FALSE
)
bsim <- sim(sshfi_ln, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(Year = mean(sshf$Year), parks_percent_change_from_baseline = seq(min(sshf$StringencyIndex), max(sshf$parks_percent_change_from_baseline), length.out = 100)) # values to predict for
X <- model.matrix(~ Year + parks_percent_change_from_baseline, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Finland"
newD$Year <- NULL
lshg_[[1]] <- newD

sshc <- ssh[Country == "Czechia"]
sshcz_ln <- lmer(log(Human+0.01) ~
  parks_percent_change_from_baseline +
  (scale(parks_percent_change_from_baseline) | weekday),
data = sshc, REML = FALSE
)
bsim <- sim(sshcz_ln, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(parks_percent_change_from_baseline = seq(min(sshc$parks_percent_change_from_baseline), max(sshc$parks_percent_change_from_baseline), length.out = 100)) # values to predict for
X <- model.matrix(~parks_percent_change_from_baseline, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Czechia"
lshg_[[2]] <- newD

ssh_h <- ssh[Country == "Hungary"]
sshhu_ln <- lmer(log(Human+0.01) ~
  Year +
  parks_percent_change_from_baseline +
  (scale(parks_percent_change_from_baseline) | year_weekday),
data = ssh_h, REML = FALSE
)

bsim <- sim(sshhu_ln, n.sim = nsim)
v <- apply(bsim@fixef, 2, quantile, prob = c(0.5))
newD <- data.frame(Year = mean(ssh_h$Year), parks_percent_change_from_baseline = seq(min(ssh_h$parks_percent_change_from_baseline), max(ssh_h$parks_percent_change_from_baseline), length.out = 100)) # values to predict for
X <- model.matrix(~ Year + parks_percent_change_from_baseline, data = newD) # exactly the model which was used has to be specified here
newD$pred <- (X %*% v)
predmatrix <- matrix(nrow = nrow(newD), ncol = nsim)
for (j in 1:nsim) predmatrix[, j] <- (X %*% bsim@fixef[j, ])
newD$lwr <- apply(predmatrix, 1, quantile, prob = 0.025)
newD$upr <- apply(predmatrix, 1, quantile, prob = 0.975)
newD$pred <- apply(predmatrix, 1, quantile, prob = 0.5)
newD$Country <- "Hungary"
newD$Year <- NULL
lshg_[[3]] <- newD

h_g_ln <- data.table(do.call(rbind, lshg_))
h_g_ln[, Country := factor(Country, levels = (c("Finland", "Czechia", "Hungary")))]
h_g_ln[, pred_o := exp(pred) - 0.01]
h_g_ln[, lwr_o := exp(lwr) - 0.01]
h_g_ln[, upr_o := exp(upr) - 0.01]

# plot
col_h <- c("#357EBDFF", "#D43F3AFF", "#46B8DAFF", "#5CB85CFF", "#EEA236FF", "#9632B8FF", "#9632B8FF")[7:1]
col_h <- col_h[c(4, 5, 7)] #show_col(col_h)
# original stringency
p_hs_o <-
  ggplot(h_s, aes(x = StringencyIndex, y = pred, col = Country)) +
  geom_ribbon(aes(ymin = lwr, ymax = upr, fill = Country, color = NULL), alpha = .15) +
  # geom_point(aes(y = Human, fill = Country), data = sh, pch = 21, col = "grey20",alpha = 0.5)+
  geom_jitter(aes(y = Human, fill = Country), data = sh, pch = 21, col = "grey20", width = 0.5, height = 0.1, alpha = 0.5) +
  geom_line(lwd = 1) +
  labs(subtitle = "Original scale", y = "# of humans", x = "Stringency index") +
  coord_cartesian(xlim = c(25, 75), ylim = c(0, 50)) +
  facet_wrap(~Country) +
  # scale_color_locuszoom()+
  # scale_fill_locuszoom(guide = "none")
  scale_x_continuous(breaks = round(seq(25, 75, by = 25), 1)) +
  # scale_y_continuous(breaks = log(c(0.01, 1, 10, 50)), labels = c(0, 1, 10, 50)) +
  # scale_y_continuous(breaks = round(seq(-100, 175, by = 25), 1)) +
  scale_colour_manual(
    values = col_h, guide = guide_legend(reverse = TRUE, override.aes = list(size = 0)),
    labels = paste(
      "<span style='color:",
      col_h,
      "'>",
      levels(h_s$Country),
      "</span>"
    )
  ) +
  scale_fill_manual(values = col_h, guide = "none") +
  theme_bw() +
  theme(
    legend.text = element_markdown(size = 6),
    legend.position = "none",
    legend.title = element_blank(),
    # legend.spacing.y = unit(0.1, 'cm'),
    legend.key.height = unit(0.5, "line"),
    legend.key.size = unit(0, "line"),
    legend.margin = margin(0, 0, 0, 0),
    legend.box.margin = margin(-10, 1, -10, -10),
    # legend.position=c(0.5,1.6),
    plot.title = element_text(color = "grey", size = 7),
    plot.subtitle = element_text(color = "grey60", size = 6),
    plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r = 0.5, unit = "pt"),
    panel.grid = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank(),
    axis.line = element_line(colour = ax_lines, size = 0.25),
    axis.ticks = element_line(colour = ax_lines, size = 0.25),
    # axis.text.x = element_text()
    axis.ticks.length = unit(1, "pt"),
    axis.text = element_text(, size = 6),
    axis.title = element_text(size = 7),
    strip.background = element_blank(),
    strip.text.x = element_text(size = 6, color = "grey30", margin = margin(1, 1, 1, 1, "mm"))
  )
#p_hs_o
#if (save_plot == TRUE) {
#  ggsave(here::here("Outputs/Fig_HS_temp_rev_widht_70mm_v2_origi.png"), p_hs_o #+ theme(plot.subtitle = element_blank())
#    ,
#    width = 10, height = 4.5, unit = "cm", dpi = 600
#  )
#}

# ln stringency
p_hs_ln = ggplot(h_s_ln, aes(x = StringencyIndex, y = pred, col = Country)) +
  geom_ribbon(aes(ymin = lwr, ymax = upr, fill = Country, color = NULL), alpha = .15) +
  # geom_point(aes(y = Human, fill = Country), data = sh, pch = 21, col = "grey20",alpha = 0.5)+
  geom_jitter(aes(y = log(Human + 0.01), fill = Country), data = sh, pch = 21, col = "grey20", width = 0.5, height = 0.1, alpha = 0.5) +
  geom_line(lwd = 1) +
  labs(subtitle = "Ln-scale", y = "# of humans", x = "Stringency index") +
  coord_cartesian(xlim = c(25, 75), ylim = c(log(0.01), log(50))) +
  facet_wrap(~Country) +
  # scale_color_locuszoom()+
  # scale_fill_locuszoom(guide = "none")
  scale_x_continuous(breaks = round(seq(25, 75, by = 25), 1)) +
  scale_y_continuous(breaks = log(c(0.01, 1, 10, 50)), labels = c(0, 1, 10, 50)) +
  # scale_y_continuous(breaks = round(seq(-100, 175, by = 25), 1)) +
  scale_colour_manual(
    values = col_h, guide = guide_legend(reverse = TRUE, override.aes = list(size = 0)),
    labels = paste(
      "<span style='color:",
      col_h,
      "'>",
      levels(h_s$Country),
      "</span>"
    )
  ) +
  scale_fill_manual(values = col_h, guide = "none") +
  theme_bw() +
  theme(
    legend.text = element_markdown(size = 6),
    legend.position = "none",
    legend.title = element_blank(),
    # legend.spacing.y = unit(0.1, 'cm'),
    legend.key.height = unit(0.5, "line"),
    legend.key.size = unit(0, "line"),
    legend.margin = margin(0, 0, 0, 0),
    legend.box.margin = margin(-10, 1, -10, -10),
    # legend.position=c(0.5,1.6),
    plot.title = element_text(color = "grey", size = 7),
    plot.subtitle = element_text(color = "grey60", size = 6),
    plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r = 0.5, unit = "pt"),
    panel.grid = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank(),
    axis.line = element_line(colour = ax_lines, size = 0.25),
    axis.ticks = element_line(colour = ax_lines, size = 0.25),
    # axis.text.x = element_text()
    axis.ticks.length = unit(1, "pt"),
    axis.text = element_text(, size = 6),
    axis.title = element_text(size = 7),
    strip.background = element_blank(),
    strip.text.x = element_text(size = 6, color = "grey30", margin = margin(1, 1, 1, 1, "mm"))
  )
#p_hs_ln
#if (save_plot == TRUE) {
#  ggsave(here::here("Outputs/Fig_HS_ln.png"), p_hs_ln #+ theme(plot.subtitle = element_blank())
#    ,
#    width = 10, height = 4.5, unit = "cm", dpi = 600
#  )
#}

# original google
p_hg_o <-
  ggplot(h_sg, aes(x = parks_percent_change_from_baseline, y = pred, col = Country)) +
  geom_ribbon(aes(ymin = lwr, ymax = upr, fill = Country, color = NULL), alpha = .15) +
  # geom_point(aes(y = Human, fill = Country), data = sh, pch = 21, col = "grey20",alpha = 0.5)+
  geom_jitter(aes(y = Human, fill = Country), data = ssh, pch = 21, col = "grey20", width = 0.5, height = 0.1, alpha = 0.5) +
  geom_line(lwd = 1) +
  labs(subtitle = "", y = "# of humans", x = "Google Mobility") +
  coord_cartesian(xlim = c(-50, 150), ylim = c(0, 50)) +
  facet_wrap(~Country) +
  # scale_color_locuszoom()+
  # scale_fill_locuszoom(guide = "none")
  #scale_x_continuous(breaks = round(seq(25, 75, by = 25), 1)) +
  # scale_y_continuous(breaks = log(c(0.01, 1, 10, 50)), labels = c(0, 1, 10, 50)) +
  # scale_y_continuous(breaks = round(seq(-100, 175, by = 25), 1)) +
  scale_colour_manual(
    values = col_h, guide = guide_legend(reverse = TRUE, override.aes = list(size = 0)),
    labels = paste(
      "<span style='color:",
      col_h,
      "'>",
      levels(h_s$Country),
      "</span>"
    )
  ) +
  scale_fill_manual(values = col_h, guide = "none") +
  theme_bw() +
  theme(
    legend.text = element_markdown(size = 6),
    legend.position = "none",
    legend.title = element_blank(),
    # legend.spacing.y = unit(0.1, 'cm'),
    legend.key.height = unit(0.5, "line"),
    legend.key.size = unit(0, "line"),
    legend.margin = margin(0, 0, 0, 0),
    legend.box.margin = margin(-10, 1, -10, -10),
    # legend.position=c(0.5,1.6),
    plot.title = element_text(color = "grey", size = 7),
    plot.subtitle = element_text(color = "grey60", size = 6),
    plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r = 0.5, unit = "pt"),
    panel.grid = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank(),
    axis.line = element_line(colour = ax_lines, size = 0.25),
    axis.ticks = element_line(colour = ax_lines, size = 0.25),
    # axis.text.x = element_text()
    axis.ticks.length = unit(1, "pt"),
    axis.text = element_text(, size = 6),
    axis.title = element_text(size = 7),
    strip.background = element_blank(),
    strip.text.x = element_text(size = 6, color = "grey30", margin = margin(1, 1, 1, 1, "mm"))
  )
#p_hg_o
#if (save_plot == TRUE) {
#  ggsave(here::here("Outputs/Fig_HG_rev_widht_70mm_v2_origi.png"), p_hg_o #+ theme(plot.subtitle = element_blank())
#    ,
#    width = 10, height = 4.5, unit = "cm", dpi = 600
#  )
#}

# ln google
p_hg_ln <- ggplot(h_g_ln, aes(x = parks_percent_change_from_baseline, y = pred, col = Country)) +
  geom_ribbon(aes(ymin = lwr, ymax = upr, fill = Country, color = NULL), alpha = .15) +
  # geom_point(aes(y = Human, fill = Country), data = sh, pch = 21, col = "grey20",alpha = 0.5)+
  geom_jitter(aes(y = log(Human + 0.01), fill = Country), data = ssh, pch = 21, col = "grey20", width = 0.5, height = 0.1, alpha = 0.5) +
  geom_line(lwd = 1) +
  labs(subtitle = "", y = "# of humans", x = "Google Mobility") +
  coord_cartesian(xlim = c(-50, 150), ylim = c(log(0.01), log(50))) +
  facet_wrap(~Country) +
  # scale_color_locuszoom()+
  # scale_fill_locuszoom(guide = "none")
  #scale_x_continuous(breaks = round(seq(25, 75, by = 25), 1)) +
  scale_y_continuous(breaks = log(c(0.01, 1, 10, 50)), labels = c(0, 1, 10, 50)) +
  # scale_y_continuous(breaks = round(seq(-100, 175, by = 25), 1)) +
  scale_colour_manual(
    values = col_h, guide = guide_legend(reverse = TRUE, override.aes = list(size = 0)),
    labels = paste(
      "<span style='color:",
      col_h,
      "'>",
      levels(h_s$Country),
      "</span>"
    )
  ) +
  scale_fill_manual(values = col_h, guide = "none") +
  theme_bw() +
  theme(
    legend.text = element_markdown(size = 6),
    legend.position = "none",
    legend.title = element_blank(),
    # legend.spacing.y = unit(0.1, 'cm'),
    legend.key.height = unit(0.5, "line"),
    legend.key.size = unit(0, "line"),
    legend.margin = margin(0, 0, 0, 0),
    legend.box.margin = margin(-10, 1, -10, -10),
    # legend.position=c(0.5,1.6),
    plot.title = element_text(color = "grey", size = 7),
    plot.subtitle = element_text(color = "grey60", size = 6),
    plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r = 0.5, unit = "pt"),
    panel.grid = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank(),
    axis.line = element_line(colour = ax_lines, size = 0.25),
    axis.ticks = element_line(colour = ax_lines, size = 0.25),
    # axis.text.x = element_text()
    axis.ticks.length = unit(1, "pt"),
    axis.text = element_text(, size = 6),
    axis.title = element_text(size = 7),
    strip.background = element_blank(),
    strip.text.x = element_text(size = 6, color = "grey30", margin = margin(1, 1, 1, 1, "mm"))
  )
#p_hg_ln
#if (save_plot == TRUE) {
#  ggsave(here::here("Outputs/Fig_GS_ln.png"), p_hs_ln #+ theme(plot.subtitle = element_blank())
#    ,
#    width = 10, height = 4.5, unit = "cm", dpi = 600
#  )
#}

# combine & export
sshh <- ggarrange(
  p_hs_o + rremove("ylab") + xlab(''), p_hg_o +  rremove("ylab") + xlab(''),
   p_hs_ln +  rremove("ylab"), p_hg_ln + rremove("ylab"),
  ncol = 2, nrow = 2
  ) + theme(plot.margin = margin(r = 2)) 

fig_6 = annotate_figure(sshh,
  left = textGrob("# of humans", rot = 90, gp = gpar(cex = 0.6))
)

if (save_plot == TRUE) {
ggsave(file = here::here("Outputs/Fig_6.png"), fig_6, width = 12, height = 12, units = "cm")
}

fig_6

Figure 6 | Human numbers in association with stringency of antipandemic governmental restrictions (Stringency index, left) and daily human presence in parks (Google Mobility, right). Dots represent individual data points (top panels on original scale, bottom on ln-scale), jittered to increase visibility. Lines with shaded areas represent predictions with 95%CIs from mixed effect models controlled for the year (in case of Finland and Hungary) and non-independence of data points by including weekday within the year as a random intercept and Stringency index or Google Mobility as a random slope (Table S3b, S3c, S3d, S3e). Note the weak and country-specific associations.


Table S3b | Number of humans in relation to Stringency index

llb = list()

shf <- sh[Country == "Finland"]
shfi_ <- lmer(scale(Human) ~
  scale(Year) +
  scale(StringencyIndex) +
  (scale(StringencyIndex) | year_weekday),
data = shf, REML = FALSE
)
llb[[1]] = m_out(name = "Table S3b - FI", dep = "# of humans", model = shfi_, nsim = 5000)

shc <- sh[Country == "Czechia"]
shcz_ <- lmer(scale(Human) ~
  scale(StringencyIndex) +
  (scale(StringencyIndex) | weekday),
data = shc, REML = FALSE
)
llb[[2]] = m_out(name = "Table S3b - CZ", dep = "# of humans", model = shcz_, nsim = 5000)
llb[[2]]$R2_mar <- llb[[2]]$R2_con <- NULL

sh_h <- sh[Country == "Hungary"]
shhu_ <- lmer(scale(Human) ~
  scale(Year) +
  scale(StringencyIndex) +
  (scale(StringencyIndex) | year_weekday),
data = sh_h, REML = FALSE
)
llb[[3]] = m_out(name = "Table S3b - HU", dep = "# of humans", model = shhu_, nsim = 5000)
llb[[3]]$R2_mar = llb[[3]]$R2_con = NULL

out_t3b = data.table(do.call(rbind, llb))
out_t3b[is.na(out_t3b)] <- ""
out_t3b$R2_mar = out_t3b$R2_con = NULL
out_t3b[, effect := gsub("scale\\(Year\\)", "year", effect)]
out_t3b[, effect := gsub("scale\\(StringencyIndex\\)", "Stringency index", effect)]
out_t3b[, effect := gsub("year_weekday", "weekday within year", effect)]
out_t3b[type == "random" & grepl("Stringency index", effect, fixed = TRUE), effect := paste("Stringency index (slope) |", gsub(" Stringency index", "", effect))]
fwrite(file = here::here("Outputs/Table_S3b_rev.csv"), out_t3b)

out_t3b$error_structure = out_t3b$response = NULL
out_t3b[model != "", model := c(
  "Finland",
  "Czechia",
  "Hungary"
)]
setnames(out_t3b, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
out_t3b %>%
  kbl() %>%
  kable_paper("hover", full_width = F)
model N type effect estimate lower upper
Finland 354 fixed (Intercept) -0.017 -0.146 0.113
fixed year 0.166 -0.058 0.395
fixed Stringency index -0.123 -0.351 0.119
random weekday within year (Intercept) 0% 0% 2%
random Stringency index (slope) | weekday within year 0% 0% 2%
random Residual 99% 96% 101%
Czechia 916 fixed (Intercept) 0.113 -0.283 0.499
fixed Stringency index 0.299 -0.258 0.848
random weekday (Intercept) 23% 17% 36%
random Stringency index (slope) | weekday 23% 17% 36%
random Residual 54% 28% 67%
Hungary 874 fixed (Intercept) -0.039 -0.202 0.126
fixed year 0.434 0.252 0.615
fixed Stringency index 0.195 -0.016 0.411
random weekday within year (Intercept) 2% 1% 9%
random Stringency index (slope) | weekday within year 2% 1% 9%
random Residual 96% 83% 98%

Table S3c | Number of humans (ln-transformed) in relation to Stringency index

llc = list()

shf <- sh[Country == "Finland"]
shfi_ln_ <- lmer(scale(log(Human+0.01)) ~
  scale(Year) +
  scale(StringencyIndex) +
  (scale(StringencyIndex) | year_weekday),
data = shf, REML = FALSE
)
llc[[1]] = m_out(name = "Table S3c - FI", dep = "# of humans (ln)", model = shfi_ln_, nsim = 5000)

shc <- sh[Country == "Czechia"]
shcz_ln_ <- lmer(scale(log(Human+0.01))~
  scale(StringencyIndex) +
  (scale(StringencyIndex) | weekday),
data = shc, REML = FALSE
)
llc[[2]] = m_out(name = "Table S3c - CZ", dep = "# of humans (ln)", model = shcz_ln_, nsim = 5000)

sh_h <- sh[Country == "Hungary"]
shhu_ln_ <- lmer(scale(log(Human+0.01)) ~
  scale(Year) +
  scale(StringencyIndex) +
  (scale(StringencyIndex) | year_weekday),
data = sh_h, REML = FALSE
)
llc[[3]] = m_out(name = "Table S3c - HU", dep = "# of humans (ln)", model = shhu_ln_, nsim = 5000)

out_t3c = data.table(do.call(rbind, llc))
out_t3c[is.na(out_t3c)] <- ""
out_t3c$R2_mar = out_t3c$R2_con = NULL
out_t3c[, effect := gsub("scale\\(Year\\)", "year", effect)]
out_t3c[, effect := gsub("scale\\(StringencyIndex\\)", "Stringency index", effect)]
out_t3c[, effect := gsub("year_weekday", "weekday within year", effect)]
out_t3c[type == "random" & grepl("Stringency index", effect, fixed = TRUE), effect := paste("Stringency index (slope) |", gsub(" Stringency index", "", effect))]
fwrite(file = here::here("Outputs/Table_S3c_rev.csv"), out_t3c)

out_t3c$error_structure = out_t3b$response = NULL
out_t3c[model != "", model := c(
  "Finland",
  "Czechia",
  "Hungary"
)]
setnames(out_t3c, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
out_t3c %>%
  kbl() %>%
  kable_paper("hover", full_width = F)
model response N type effect estimate lower upper
Finland # of humans (ln) 354 fixed (Intercept) -0.167 -0.5 0.165
fixed year 0.349 0.071 0.615
fixed Stringency index -0.164 -0.507 0.165
random weekday within year (Intercept) 6% -71% 27%
random Stringency index (slope) | weekday within year 6% -71% 27%
random Residual 87% 45% 243%
Czechia # of humans (ln) 916 fixed (Intercept) 0 -0.138 0.146
fixed Stringency index 0.293 -0.157 0.746
random weekday (Intercept) 3% -10% 28%
random Stringency index (slope) | weekday 3% -10% 28%
random Residual 95% 44% 120%
Hungary # of humans (ln) 874 fixed (Intercept) -0.123 -0.353 0.113
fixed year 0.352 0.149 0.551
fixed Stringency index 0.192 -0.094 0.481
random weekday within year (Intercept) 1% -87% 21%
random Stringency index (slope) | weekday within year 1% -87% 21%
random Residual 99% 57% 274%

Table S3d | Number of humans in relation to Google Mobility

lld = list()

sshf <- ssh[Country == "Finland"]
shfi_g <- lmer(scale(Human) ~
  scale(Year) +
  scale(parks_percent_change_from_baseline) +
  (scale(parks_percent_change_from_baseline) | year_weekday),
data = sshf, REML = FALSE
)
lld[[1]] = m_out(name = "Table S3d - FI", dep = "# of humans", model = shfi_g, nsim = 5000)
lld[[1]]$R2_mar <- lld[[1]]$R2_con <- NULL

sshc <- ssh[Country == "Czechia"]
shcz_g <- lmer(scale(Human) ~
  scale(parks_percent_change_from_baseline) +
  (scale(parks_percent_change_from_baseline) | weekday),
data = sshc, REML = FALSE
)
lld[[2]] = m_out(name = "Table S3d - CZ", dep = "# of humans", model = shcz_g, nsim = 5000)
lld[[2]]$R2_mar = lld[[2]]$R2_con = NULL

ssh_h <- ssh[Country == "Hungary"]
shhu_g <- lmer(scale(Human) ~
  scale(Year) +
  scale(parks_percent_change_from_baseline) +
  (scale(parks_percent_change_from_baseline) | year_weekday),
data = ssh_h, REML = FALSE
)
lld[[3]] = m_out(name = "Table S3d - HU", dep = "# of humans", model = shhu_g, nsim = 5000)
## Random effect variances not available. Returned R2 does not account for random effects.
## Random effect variances not available. Returned R2 does not account for random effects.
lld[[3]]$R2_mar <- lld[[3]]$R2_con <- NULL

out_t3d = data.table(do.call(rbind, lld))
out_t3d[is.na(out_t3d)] <- ""
out_t3d$R2_mar = out_t3d$R2_con = NULL
out_t3d[, effect := gsub("scale\\(Year\\)", "year", effect)]
out_t3d[, effect := gsub("scale\\(parks_percent_change_from_baseline\\)", "Google Mobility", effect)]
out_t3d[, effect := gsub("year_weekday", "weekday within year", effect)]
out_t3d[type == "random" & grepl("Google Mobility", effect, fixed = TRUE), effect := paste("Google Mobility (slope) |", gsub(" Google Mobility", "", effect))]
fwrite(file = here::here("Outputs/Table_S3d_rev.csv"), out_t3d)

out_t3d$error_structure = out_t3d$response = NULL
out_t3d[model != "", model := c(
  "Finland",
  "Czechia",
  "Hungary"
)]
setnames(out_t3d, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
out_t3d %>%
  kbl() %>%
  kable_paper("hover", full_width = F)
model N type effect estimate lower upper
Finland 322 fixed (Intercept) -0.04 -0.199 0.113
fixed year 0.024 -0.146 0.19
fixed Google Mobility 0.055 -0.089 0.201
random weekday within year (Intercept) 0% 0% 4%
random Google Mobility (slope) | weekday within year 0% 0% 4%
random Residual 100% 93% 101%
Czechia 916 fixed (Intercept) 0.137 -0.435 0.708
fixed Google Mobility 0.089 -0.597 0.791
random weekday (Intercept) 4% 38% 79%
random Google Mobility (slope) | weekday 4% 38% 79%
random Residual 92% -59% 24%
Hungary 874 fixed (Intercept) -0.066 -0.216 0.088
fixed year 0.452 0.318 0.586
fixed Google Mobility -0.171 -0.322 -0.015
random weekday within year (Intercept) 1% -4% 8%
random Google Mobility (slope) | weekday within year 1% -4% 8%
random Residual 99% 84% 108%

Table S3e | Number of humans (ln-transformed) in relation to Google Mobility

lle = list()

sshf <- ssh[Country == "Finland"]
shfi_g_ln <- lmer(scale(log(Human + 0.01)) ~
  scale(Year) +
  scale(parks_percent_change_from_baseline) +
  (scale(parks_percent_change_from_baseline) | year_weekday),
data = sshf, REML = FALSE
)
lle[[1]] = m_out(name = "Table S3e - FI", dep = "# of humans (ln)", model = shfi_g_ln, nsim = 5000)
lle[[1]]$R2_mar <- lle[[1]]$R2_con <- NULL

sshc <- ssh[Country == "Czechia"]
shcz_g_ln <- lmer(scale(log(Human + 0.01)) ~
  scale(parks_percent_change_from_baseline) +
  (scale(parks_percent_change_from_baseline) | weekday),
data = sshc, REML = FALSE
)
lle[[2]] = m_out(name = "Table S3e - CZ", dep = "# of humans (ln)", model = shcz_g_ln, nsim = 5000)
lle[[2]]$R2_mar <- lle[[2]]$R2_con <- NULL

ssh_h <- ssh[Country == "Hungary"]
shhu_g_ln <- lmer(scale(log(Human + 0.01)) ~
  scale(Year) +
  scale(parks_percent_change_from_baseline) +
  (scale(parks_percent_change_from_baseline) | year_weekday),
data = ssh_h, REML = FALSE
)
lle[[3]] = m_out(name = "Table S3e - HU", dep = "# of humans (ln)", model = shhu_g_ln, nsim = 5000)
lle[[3]]$R2_mar <- lle[[3]]$R2_con <- NULL

out_t3e = data.table(do.call(rbind, lle))
out_t3e[is.na(out_t3e)] <- ""
out_t3e[, effect := gsub("scale\\(Year\\)", "year", effect)]
out_t3e[, effect := gsub("scale\\(parks_percent_change_from_baseline\\)", "Google Mobility", effect)]
out_t3e[, effect := gsub("year_weekday", "weekday within year", effect)]
out_t3e[type == "random" & grepl("Google Mobility", effect, fixed = TRUE), effect := paste("Google Mobility (slope) |", gsub(" Google Mobility", "", effect))]
fwrite(file = here::here("Outputs/Table_S3e_rev.csv"), out_t3e)

out_t3e$error_structure = out_t3e$response = NULL
out_t3e[model != "", model := c(
  "Finland",
  "Czechia",
  "Hungary"
)]
setnames(out_t3e, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
out_t3e %>%
  kbl() %>%
  kable_paper("hover", full_width = F)
model N type effect estimate lower upper
Finland 322 fixed (Intercept) -0.193 -0.443 0.05
fixed year -0.028 -0.272 0.214
fixed Google Mobility 0.223 0.057 0.387
random weekday within year (Intercept) 0% -6% 14%
random Google Mobility (slope) | weekday within year 0% -6% 14%
random Residual 100% 71% 112%
Czechia 916 fixed (Intercept) 0.01 -0.209 0.234
fixed Google Mobility 0.185 -0.366 0.725
random weekday (Intercept) 8% 1% 34%
random Google Mobility (slope) | weekday 8% 1% 34%
random Residual 83% 32% 97%
Hungary 874 fixed (Intercept) -0.034 -0.176 0.102
fixed year 0.631 0.455 0.805
fixed Google Mobility -0.278 -0.425 -0.129
random weekday within year (Intercept) 1% -1% 5%
random Google Mobility (slope) | weekday within year 1% -1% 5%
random Residual 98% 89% 102%

Effect sizes for Stringency index, Google Mobility & # of humans

# predictions for fig and table for stringency
 # full
 mss <- lmer(scale(log(FID)) ~
     scale(Year) +
     scale(log(SD)) +
     scale(log(FlockSize)) +
     scale(log(BodyMass)) +
     scale(sin(rad)) + scale(cos(rad)) +
     # scale(Day)+
     scale(Temp) +
     scale(StringencyIndex) +
     (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(StringencyIndex) | Country) + (1 | IDLocality) + (1 | sp_loc),
 data = s, REML = FALSE,
 control = lmerControl(
     optimizer = "optimx", optCtrl = list(method = "nlminb")
 )
 )
 est_mss <- est_out(mss, "ALL: (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(StringencyIndex)|Country) + (1|IDLocality) +(1|sp_loc)")
 est_mss[, control_for_starting_distance := "yes"]

 msx <- lmer(scale(log(FID)) ~
    scale(Year) +
    #scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
    (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(StringencyIndex) | Country) + (1| IDLocality) + (1 | sp_loc),
 data = s, REML = FALSE,
 control = lmerControl(
    optimizer = "optimx", optCtrl = list(method = "nlminb")
)
)
est_msx <- est_out(msx, "ALL: (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(StringencyIndex)|Country) + (1|IDLocality) +(1|sp_loc)")
est_msx[, control_for_starting_distance := "no"]


# CZ - singular fits only due to genera estimated as zero (removing it changes no results)
  css <- lmer(scale(log(FID)) ~
    #scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
    (1|weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (1| IDLocality) + (1|sp_loc),
    #(1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
    data = s[Country == "Czechia"], REML = FALSE
    )
  est_css <- est_out(css, "Czechia: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
  est_css[, control_for_starting_distance := "yes"]
  
  csx <- lmer(scale(log(FID)) ~
    #scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
    (1|weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (1| IDLocality) + (1|sp_loc),
    #(1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
    data = s[Country == "Czechia"], REML = FALSE
    )
  est_csx <- est_out(csx, "Czechia: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
  est_csx[, control_for_starting_distance := "no"]

# FI
fss <- lmer(scale(log(FID)) ~
    scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
    (1|weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (1| IDLocality) + (1|sp_loc),
data = s[Country == "Finland"], REML = FALSE
)
est_fss <- est_out(fss, "Finland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(scale(StringencyIndex)|IDLocality)+(1|sp_loc)")
est_fss[, control_for_starting_distance := "yes"]

fsx <- lmer(scale(log(FID)) ~
    scale(Year) +
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
    (1|weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (1| IDLocality) + (1|sp_loc),
data = s[Country == "Finland"], REML = FALSE
)
est_fsx <- est_out(fsx, "Finland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(scale(StringencyIndex)|IDLocality)+(1|sp_loc)")
est_fsx[, control_for_starting_distance := "no"]

# HU - singular fits only due to sp_loc estimated as zero (removing it changes no results)
hss <- lmer(scale(log(FID)) ~
    scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
    (1|weekday) +  (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = s[Country == "Hungary"], REML = FALSE
)
est_hss <- est_out(hss, "Hungary: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_hss[, control_for_starting_distance := "yes"]

hsx <- lmer(scale(log(FID)) ~
    scale(Year) +
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
    (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = s[Country == "Hungary"], REML = FALSE
)
est_hsx <- est_out(hsx, "Hungary: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_hsx[, control_for_starting_distance := "no"]

# AU - singular fits only due to Year and random slope estimated as zero (removing those changes no results)
ass <- lmer(scale(log(FID)) ~
    scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
     (1|weekday) +  (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = s[Country == "Australia"], REML = FALSE
)
est_ass <- est_out(ass, "Australia: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_ass[, control_for_starting_distance := "yes"]

asx <- lmer(scale(log(FID)) ~
    scale(Year) +
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
    (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = s[Country == "Australia"], , REML = FALSE,
        control = lmerControl( 
            optimizer ='optimx', optCtrl=list(method='nlminb')) 
)
est_asx <- est_out(asx, "Australia: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_asx[, control_for_starting_distance := "no"]

# PL 
pss <- lmer(scale(log(FID)) ~
    scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
    (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = s[Country == "Poland"], REML = FALSE
)
est_pss <- est_out(pss, "Poland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)")
est_pss[, control_for_starting_distance := "yes"]

psx <- lmer(scale(log(FID)) ~
    scale(Year) +
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(StringencyIndex) +
    (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = s[Country == "Poland"], REML = FALSE
)
est_psx <- est_out(psx, "Poland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)")
est_psx[, control_for_starting_distance := "no"]

  # combine
    est_mss[, Country := 'All\n(mixed model)']
    est_msx[, Country := "All\n(mixed model)"]
    est_ass[, Country := "Australia"]
    est_asx[, Country := "Australia"]
    est_css[, Country := "Czechia"]
    est_csx[, Country := "Czechia"]
    est_hss[, Country := "Hungary"]
    est_hsx[, Country := "Hungary"]
    est_pss[, Country := "Poland"]
    est_psx[, Country := "Poland"]
    est_fss[, Country := "Finland"]
    est_fsx[, Country := "Finland"]

    os = rbind(est_mss, est_msx, 
            est_ass, est_asx, 
            est_css, est_csx, 
            est_hss, est_hsx,
            est_pss, est_psx, 
            est_fss, est_fsx)
    save(os, file = here::here('Data/dat_est_Stringency_rev.Rdata'))

# estimates for table
  mss_out <- m_out(name = "Table S4 - full a", dep = "Escape distance", model = mss, nsim = 5000)
  msx_out <- m_out(name = "Table S4 - full b", dep = "Escape distance", model = msx, nsim = 5000)
  css_out <- m_out(name = "Table S4 - CZ a", dep = "Escape distance", model = css, nsim = 5000)
  csx_out <- m_out(name = "Table S4 - CZ b", dep = "Escape distance", model = csx, nsim = 5000)
  fss_out <- m_out(name = "Table S4 - FI a", dep = "Escape distance", model = fss, nsim = 5000)
  fsx_out <- m_out(name = "Table S4 - FI b", dep = "Escape distance", model = fsx, nsim = 5000)
  hss_out <- m_out(name = "Table S4 - HU a", dep = "Escape distance", model = hss, nsim = 5000)
  hsx_out <- m_out(name = "Table S4 - HU b", dep = "Escape distance", model = hsx, nsim = 5000)
  ass_out <- m_out(name = "Table S4 - AU a", dep = "Escape distance", model = ass, nsim = 5000)
  asx_out <- m_out(name = "Table S4 - AU b", dep = "Escape distancey", model = asx, nsim = 5000)
  pss_out <- m_out(name = "Table S4 - PL a", dep = "Escape distance", model = pss, nsim = 5000)
  psx_out <- m_out(name = "Table S4 - PL b", dep = "Escape distancey", model = psx, nsim = 5000)

  out_FID_s <- rbind(mss_out, msx_out, fss_out, fsx_out, pss_out, psx_out, css_out, csx_out, hss_out, hsx_out, ass_out, asx_out, fill = TRUE)
  out_FID_s[is.na(out_FID_s)] <- ""
  out_FID_s$R2_mar = out_FID_s$R2_con = NULL
  out_FID_s[, effect := gsub("scale\\(StringencyIndex\\)", "Stringency index", effect)]
  out_FID_s[, effect := gsub("scale\\(Year\\)", "year", effect)]
  out_FID_s[, effect := gsub("scale\\(log\\(SD\\)", "starting distance (ln)", effect)]
  out_FID_s[, effect := gsub("scale\\(Temp\\)", "temperature", effect)]
  out_FID_s[, effect := gsub("scale\\(log\\(FlockSize\\)\\)", "flock size (ln)", effect)]
  out_FID_s[, effect := gsub("scale\\(log\\(BodyMass\\)\\)", "body mass (ln)", effect)]
  out_FID_s[, effect := gsub("scale\\(sin\\(rad\\)\\)", "time (sine of radians)", effect)]
  out_FID_s[, effect := gsub("scale\\(cos\\(rad\\)\\)", "time (cosine of radians)", effect)]
  out_FID_s[, effect := gsub("Species", "species", effect)]
  out_FID_s[, effect := gsub("Country", "country", effect)]
  out_FID_s[, effect := gsub("sp_day_year", "species within day & year", effect)]
  out_FID_s[, effect := gsub("IDLocality", "site", effect)]
  out_FID_s[, effect := gsub("sp_loc", "species within site", effect)]
  out_FID_s[type == "random" & grepl("Stringency index", effect, fixed = TRUE), effect := paste("Stringency index (slope) |", gsub(" Stringency index", "", effect))]
  fwrite(file = here::here("Outputs/Table_S4_rev.csv"), out_FID_s)

# predictions for Fig and Table - Google Mobility
 # full
 mgs <- lmer(scale(log(FID)) ~
     scale(Year) +
     scale(log(SD)) +
     scale(log(FlockSize)) +
     scale(log(BodyMass)) +
     scale(sin(rad)) + scale(cos(rad)) +
     # scale(Day)+
     scale(Temp) +
     scale(parks_percent_change_from_baseline) +
     (1|weekday) +  (1| genus) + (1 | Species) + (1 | sp_day_year) + 
     (scale(parks_percent_change_from_baseline)| Country) + (1 | IDLocality) + (1 | sp_loc),
 data = ss, REML = FALSE,
 control = lmerControl(
     optimizer = "optimx", optCtrl = list(method = "nlminb")
 )
 )
 est_mgs <- est_out(mgs, "ALL: (1|weekday) + (1|genus) + (1|Species)  + (1|sp_day_year) + (scale(Google)|Country) + (1|IDLocality) +(1|sp_loc)")
 est_mgs[, control_for_starting_distance := "yes"]

 mgx <- lmer(scale(log(FID)) ~
    scale(Year) +
    #scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
     (1|weekday) + (1| genus) + (1 | Species) + (1 | sp_day_year) + 
     (scale(parks_percent_change_from_baseline) | Country) + (1 | IDLocality) + (1 | sp_loc),
 data = ss, REML = FALSE,
 control = lmerControl(
    optimizer = "optimx", optCtrl = list(method = "nlminb")
)
)
est_mgx <- est_out(mgx, "ALL: (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(Google)|Country) + (1|IDLocality) +(1|sp_loc)")
est_mgx[, control_for_starting_distance := "no"]


# CZ - singular fits only due to genera estimated as zero (removing it changes no results)
  cgs <- lmer(scale(log(FID)) ~
    #scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
    (1|weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (1| IDLocality) + (1|sp_loc),
    #(1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
    data = ss[Country == "Czechia"], REML = FALSE
    )
  est_cgs <- est_out(cgs, "Czechia:(1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
  est_cgs[, control_for_starting_distance := "yes"]
  
  cgx <- lmer(scale(log(FID)) ~
    #scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
    (1|weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (1| IDLocality) + (1|sp_loc),
    #(1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
    data = ss[Country == "Czechia"], REML = FALSE
    )
  est_cgx <- est_out(cgx, "Czechia: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
  est_cgx[, control_for_starting_distance := "no"]

# FI
fgs <- lmer(scale(log(FID)) ~
    scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
    (1|weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (1| IDLocality) + (1|sp_loc),
data = ss[Country == "Finland"], REML = FALSE
)
est_fgs <- est_out(fgs, "Finland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_fgs[, control_for_starting_distance := "yes"]

fgx <- lmer(scale(log(FID)) ~
    scale(Year) +
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
    (1|weekday) + (1 | genus) + (1| Species) + (1 | sp_day_year) + (1| IDLocality) + (1|sp_loc),
data = ss[Country == "Finland"], REML = FALSE
)
est_fgx <- est_out(fgx, "Finland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_fgx[, control_for_starting_distance := "no"]

# HU - singular fits only due to sp_loc estimated as zero (removing it changes no results)
hgs <- lmer(scale(log(FID)) ~
    scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
     (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = ss[Country == "Hungary"], REML = FALSE
)
est_hgs <- est_out(hgs, "Hungary: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_hgs[, control_for_starting_distance := "yes"]

hgx <- lmer(scale(log(FID)) ~
    scale(Year) +
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
    (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = ss[Country == "Hungary"], REML = FALSE
)
est_hgx <- est_out(hgx, "Hungary: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_hgx[, control_for_starting_distance := "no"]

# AU - singular fits only due to Year and random slope estimated as zero (removing those changes no results)
ags <- lmer(scale(log(FID)) ~
    scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
      (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = ss[Country == "Australia"], REML = FALSE
)
est_ags <- est_out(ags, "Australia: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_ags[, control_for_starting_distance := "yes"]

agx <- lmer(scale(log(FID)) ~
    scale(Year) +
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
    (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = ss[Country == "Australia"], , REML = FALSE,
        control = lmerControl( 
            optimizer ='optimx', optCtrl=list(method='nlminb')) 
)
est_agx <- est_out(agx, "Australia: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_agx[, control_for_starting_distance := "no"]

# PL 
pgs <- lmer(scale(log(FID)) ~
    scale(Year) +
    scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
    (1|weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = ss[Country == "Poland"], REML = FALSE
)
est_pgs <- est_out(pgs, "Poland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)")
est_pgs[, control_for_starting_distance := "yes"]

pgx <- lmer(scale(log(FID)) ~
    scale(Year) +
    # scale(log(SD)) +
    scale(log(FlockSize)) +
    scale(log(BodyMass)) +
    scale(sin(rad)) + scale(cos(rad)) +
    # scale(Day)+
    scale(Temp) +
    scale(parks_percent_change_from_baseline) +
    (1|weekday) + (1 | genus) + (1 | Species)+ (1 | sp_day_year),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = ss[Country == "Poland"], REML = FALSE
)
est_pgx <- est_out(pgx, "Poland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)")
est_pgx[, control_for_starting_distance := "no"]

  # combine
    est_mgs[, Country := 'All\n(mixed model)']
    est_mgx[, Country := "All\n(mixed model)"]
    est_ags[, Country := "Australia"]
    est_agx[, Country := "Australia"]
    est_cgs[, Country := "Czechia"]
    est_cgx[, Country := "Czechia"]
    est_hgs[, Country := "Hungary"]
    est_hgx[, Country := "Hungary"]
    est_pgs[, Country := "Poland"]
    est_pgx[, Country := "Poland"]
    est_fgs[, Country := "Finland"]
    est_fgx[, Country := "Finland"]

    og = rbind(est_mgs, est_mgx, 
            est_ags, est_agx, 
            est_cgs, est_cgx, 
            est_hgs, est_hgx,
            est_pgs, est_pgx, 
            est_fgs, est_fgx)
    save(og, file = here::here('Data/dat_est_Google_rev.Rdata'))
  # estimatees for table
  mgs_out <- m_out(name = "Table S5 - full a", dep = "Escape distance", model = mgs, nsim = 5000)
  mgx_out <- m_out(name = "Table S5 - full b", dep = "Escape distance", model = mgx, nsim = 5000)
  cgs_out <- m_out(name = "Table S5 - CZ a", dep = "Escape distance", model = cgs, nsim = 5000)
  cgx_out <- m_out(name = "Table S5 - CZ b", dep = "Escape distance", model = cgx, nsim = 5000)
  fgs_out <- m_out(name = "Table S5 - FI a", dep = "Escape distance", model = fgs, nsim = 5000)
  fgx_out <- m_out(name = "Table S5 - FI b", dep = "Escape distance", model = fgx, nsim = 5000)
  hgs_out <- m_out(name = "Table S5 - HU a", dep = "Escape distance", model = hgs, nsim = 5000)
  hgx_out <- m_out(name = "Table S5 - HU b", dep = "Escape distance", model = hgx, nsim = 5000)
  ags_out <- m_out(name = "Table S5 - AU a", dep = "Escape distance", model = ags, nsim = 5000)
  agx_out <- m_out(name = "Table S5 - AU b", dep = "Escape distancey", model = agx, nsim = 5000)
  pgs_out <- m_out(name = "Table S5 - PL a", dep = "Escape distance", model = pgs, nsim = 5000)
  pgx_out <- m_out(name = "Table S5 - PL b", dep = "Escape distancey", model = pgx, nsim = 5000)

  out_FID_g <- rbind(mgs_out, mgx_out, fgs_out, fgx_out, pgs_out, pgx_out, cgs_out, cgx_out, hgs_out, hgx_out, ags_out, agx_out, fill = TRUE)
  out_FID_g[is.na(out_FID_g)] <- ""
  out_FID_g[, effect := gsub("scale\\(parks_percent_change_from_baseline\\)", "Google Mobility", effect)]
  out_FID_g[, effect := gsub("scale\\(Year\\)", "year", effect)]
  out_FID_g[, effect := gsub("scale\\(log\\(SD\\)", "starting distance (ln)", effect)]
  out_FID_g[, effect := gsub("scale\\(Temp\\)", "temperature", effect)]
  out_FID_g[, effect := gsub("scale\\(log\\(FlockSize\\)\\)", "flock size (ln)", effect)]
  out_FID_g[, effect := gsub("scale\\(log\\(BodyMass\\)\\)", "body mass (ln)", effect)]
  out_FID_g[, effect := gsub("scale\\(sin\\(rad\\)\\)", "time (sine of radians)", effect)]
  out_FID_g[, effect := gsub("scale\\(cos\\(rad\\)\\)", "time (cosine of radians)", effect)]
  out_FID_g[, effect := gsub("Species", "species", effect)]
  out_FID_g[, effect := gsub("Country", "country", effect)]
  out_FID_g[, effect := gsub("sp_day_year", "species within day & year", effect)]
  out_FID_g[, effect := gsub("IDLocality", "site", effect)]
  out_FID_g[, effect := gsub("sp_loc", "species within site", effect)]
  out_FID_g[, effect := gsub("Google Mobility (slope) | country", "country Google Mobility", effect)]
  fwrite(file = here::here("Outputs/Table_S5_rev.csv"), out_FID_g)

# predictions for Fig and Table - # of humans
# full
mhs <- lmer(scale(log(FID)) ~
  scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) +
  (scale(Human) | Country) + (1 | IDLocality) + (1 | sp_loc),
data = dh, REML = FALSE
)

est_mhs <- est_out(mhs, "ALL: (1|Year) + (1|weekday) + (1|genus) + (1|Species)  + (1|sp_day_year) + (scale(Human) |Country) + (1|IDLocality) +(1|sp_loc)")
est_mhs[, control_for_starting_distance := "yes"]

mhx <- lmer(scale(log(FID)) ~
  # scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) +
  (scale(Human) | Country) + (1 | IDLocality) + (1 | sp_loc),
data = dh, REML = FALSE
)
est_mhx <- est_out(mhx, "ALL: (1|Year) + (1|weekday) + (1|genus) + (1|Species) + (1|sp_day_year) + (scale(Human) |Country) + (1|IDLocality) +(1|sp_loc)")
est_mhx[, control_for_starting_distance := "no"]


# CZ 
chs <- lmer(scale(log(FID)) ~
  scale(Year) +
  scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = dh[Country == "Czechia"], REML = FALSE
)
est_chs <- est_out(chs, "Czechia:(1|weekday)+(1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_chs[, control_for_starting_distance := "yes"]

chx <- lmer(scale(log(FID)) ~
  scale(Year) +
  scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = dh[Country == "Czechia"], REML = FALSE
)
est_chx <- est_out(chx, "Czechia: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_chx[, control_for_starting_distance := "no"]

# FI
fhs <- lmer(scale(log(FID)) ~
  scale(Year) +
  scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
data = dh[Country == "Finland"], REML = FALSE
)
est_fhs <- est_out(fhs, "Finland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_fhs[, control_for_starting_distance := "yes"]

fhx <- lmer(scale(log(FID)) ~
  scale(Year) +
  # scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
data = dh[Country == "Finland"], REML = FALSE
)
est_fhx <- est_out(fhx, "Finland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_fhx[, control_for_starting_distance := "no"]

# HU - singular fits only due to sp_loc estimated as zero (removing it changes no results)
hhs <- lmer(scale(log(FID)) ~
  scale(Year) +
  scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = dh[Country == "Hungary"], REML = FALSE
)
est_hhs <- est_out(hhs, "Hungary: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_hhs[, control_for_starting_distance := "yes"]

hhx <- lmer(scale(log(FID)) ~
  scale(Year) +
  # scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality) + (1 | sp_loc),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = dh[Country == "Hungary"], REML = FALSE
)
est_hhx <- est_out(hhx, "Hungary: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)+(1|IDLocality)+(1|sp_loc)")
est_hhx[, control_for_starting_distance := "no"]

# PL
phs <- lmer(scale(log(FID)) ~
  scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year),
# (1 | Year) + (1 | weekday) + (1|genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = dh[Country == "Poland"], REML = FALSE
)
est_phs <- est_out(phs, "Poland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)")
est_phs[, control_for_starting_distance := "yes"]

phx <- lmer(scale(log(FID)) ~
  # scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year),
# (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (1 | IDLocality),
data = dh[Country == "Poland"], REML = FALSE
)
est_phx <- est_out(phx, "Poland: (1|weekday) + (1|genus)+(1|Species)+(1|sp_day_year)")
est_phx[, control_for_starting_distance := "no"]

# combine
est_mhs[, Country := "All\n(mixed model)"]
est_mhx[, Country := "All\n(mixed model)"]
est_chs[, Country := "Czechia"]
est_chx[, Country := "Czechia"]
est_hhs[, Country := "Hungary"]
est_hhx[, Country := "Hungary"]
est_phs[, Country := "Poland"]
est_phx[, Country := "Poland"]
est_fhs[, Country := "Finland"]
est_fhx[, Country := "Finland"]

oh <- rbind(
  est_mhs, est_mhx,
  est_chs, est_chx,
  est_hhs, est_hhx,
  est_phs, est_phx,
  est_fhs, est_fhx
)
save(oh, file = here::here("Data/dat_est_numberOFhumans_rev.Rdata")) # save(oh, file = here::here("Data/dat_est_humans_rev_no_2018-CZ.Rdata"))

# estimatees for table
mhs_out <- m_out(name = "Table S6 - full a", dep = "Escape distance", model = mhs, nsim = 5000)
mhx_out <- m_out(name = "Table S6 - full b", dep = "Escape distance", model = mhx, nsim = 5000)
chs_out <- m_out(name = "Table S6 - CZ a", dep = "Escape distance", model = chs, nsim = 5000)
chx_out <- m_out(name = "Table S6 - CZ b", dep = "Escape distance", model = chx, nsim = 5000)
fhs_out <- m_out(name = "Table S6 - FI a", dep = "Escape distance", model = fhs, nsim = 5000)
fhx_out <- m_out(name = "Table S6 - FI b", dep = "Escape distance", model = fhx, nsim = 5000)
hhs_out <- m_out(name = "Table S6 - HU a", dep = "Escape distance", model = hhs, nsim = 5000)
hhx_out <- m_out(name = "Table S6 - HU b", dep = "Escape distance", model = hhx, nsim = 5000)
phs_out <- m_out(name = "Table S6 - PL a", dep = "Escape distance", model = phs, nsim = 5000)
phx_out <- m_out(name = "Table S6 - PL b", dep = "Escape distancey", model = phx, nsim = 5000)

out_FID_h <- rbind(mhs_out, mhx_out, fhs_out, fhx_out, phs_out, phx_out, chs_out, chx_out, hhs_out, hhx_out, fill = TRUE)
out_FID_h[is.na(out_FID_h)] <- ""
out_FID_h[, effect := gsub("scale\\(Human\\)", "# of humans present", effect)]
out_FID_h[, effect := gsub("scale\\(Year\\)", "year", effect)]
out_FID_h[, effect := gsub("scale\\(log\\(SD\\)", "starting distance (ln)", effect)]
out_FID_h[, effect := gsub("scale\\(Temp\\)", "temperature", effect)]
out_FID_h[, effect := gsub("scale\\(log\\(FlockSize\\)\\)", "flock size (ln)", effect)]
out_FID_h[, effect := gsub("scale\\(log\\(BodyMass\\)\\)", "body mass (ln)", effect)]
out_FID_h[, effect := gsub("scale\\(sin\\(rad\\)\\)", "time (sine of radians)", effect)]
out_FID_h[, effect := gsub("scale\\(cos\\(rad\\)\\)", "time (cosine of radians)", effect)]
out_FID_h[, effect := gsub("Species", "species", effect)]
out_FID_h[, effect := gsub("Country", "country", effect)]
out_FID_h[, effect := gsub("sp_day_year", "species within day & year", effect)]
out_FID_h[, effect := gsub("IDLocality", "site", effect)]
out_FID_h[, effect := gsub("sp_loc", "species within site", effect)]
out_FID_h[, effect := gsub("country # of humans present", "# of humans (slope) | country", effect)]
fwrite(file = here::here("Outputs/Table_S6.csv"), out_FID_h) # fwrite(file = here::here("Outputs/Table_S6_rev_no2018CZ.csv"), out_FID_h)
  # fig.width=8*2*0.393701, fig.height = 2.56*0.393701
# a)  
  load(here::here("Data/dat_est_Stringency_rev.Rdata"))
  os[predictor %in% c("scale(StringencyIndex)"), predictor := "Stringency Index"]
  oso <- os[predictor %in% c("Stringency Index")]
  oso[, N:=as.numeric(sub('.*N = ', '', model))]
  # add meta-analytical mean
    oso_s = oso[control_for_starting_distance == 'yes']
    met = summary(meta.summaries(d = oso_s$estimate, se = oso_s$sd, method = "fixed", weights = oso_s$N))$summci
    oso_met = data.table(predictor = "Period", estimate = met[2], lwr = met[1], upr = met[3], sd = NA, model = NA, control_for_starting_distance = "yes", Country = "Combined\n(metanalytical)", N = NA)

    oso_sx = oso[control_for_starting_distance == "no"]
    metx = summary(meta.summaries(d = oso_sx$estimate, se = oso_sx$sd, method = "fixed", weights = oso_sx$N))$summci
    oso_metx = data.table(predictor = "Period", estimate = metx[2], lwr = metx[1], upr = metx[3], sd = NA, model = NA, control_for_starting_distance = "no", Country = "Combined\n(metanalytical)", N = NA)
    
    oso = rbind(oso, oso_met, oso_metx)
      
  oso[, Country := factor(Country, levels = rev(c("Finland", "Poland", "Czechia", "Hungary", "Australia", "Combined\n(metanalytical)", "All\n(mixed model)")))]

  # prepare for adding N
  oso[, N := as.character(N)]
  oso[control_for_starting_distance == "no" | is.na(N), N := ""]
  oso[, n_pos := 0.35]

  width_ <- .5 # spacing between error bars

  #col_ <- c(brewer.pal(n = 12, name = "Paired"), "grey30", "grey80")
  #Tol_bright <- c("#EE6677", "#228833", "#4477AA", "#CCBB44", "#66CCEE", "#AA3377", "#BBBBBB")
  #Tol_muted <- c("#88CCEE", "#44AA99", "#117733", "#332288", "#DDCC77", "#999933", "#CC6677", "#882255", "#AA4499", "#DDDDDD")
  #Tol_light <- c("#BBCC33", "#AAAA00", "#77AADD", "#EE8866", "#EEDD88", "#FFAABB", "#99DDFF", "#44BB99", "#DDDDDD")

  # From Color Universal Design (CUD): https://jfly.uni-koeln.de/color/
  #Okabe_Ito <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", "#000000")
  #col_ = Okabe_Ito[7:1]
  # JAMA and LocusZoom modified order
  #col_ =  c("#374E55FF", "#374E55FF", "#DF8F44FF", "#79AF97FF", "#00A1D5FF", "#B24745FF",  "#80796BFF") #"#6A6599FF",
  #col_ <- c("#357EBDFF", "#9632B8FF", "#46B8DAFF", "#5CB85CFF", "#EEA236FF", "#D43F3AFF", "#D43F3AFF")[7:1] # "#D43F3AFF", "#B8B8B8FF"
  col_ = c("#357EBDFF", "#D43F3AFF", "#46B8DAFF", "#5CB85CFF", "#EEA236FF", "#9632B8FF", "#9632B8FF")[7:1] # "#D43F3AFF", "#B8B8B8FF"
  #show_col(col_)
  gs6a = 
  ggplot(oso, aes(x = estimate, y = Country, col = Country, shape = control_for_starting_distance)) +
      geom_vline(xintercept = 0, color = "grey", linetype = "dotted") +
      geom_errorbarh(aes(xmin = lwr, xmax = upr), height = 0, position = ggstance::position_dodgev(width_)) +
      # geom_point(position = ggstance::position_dodgev(.6)) +
      geom_point(position = position_dodge(width = width_), bg = "white", size = 1.1) +
      # scale_color_viridis(discrete=TRUE, begin=0, end = 0.5)  +
      # scale_fill_viridis(discrete=TRUE, begin=0, end = 0.5) +
      # geom_text( aes(x = n_pos,label = N), vjust = 0, size = 1.75, position = ggstance::position_dodgev(width_))+ # 3 positions for 3 bars
      # annotate("text", x=log10(3), y=85, label= "Used", col = "grey30", size = 2.5)+
      geom_text( aes(x = n_pos,label = N), vjust = 1, size = 1.75, position = ggstance::position_dodgev(width_))+
      scale_shape_manual(name = "Controlled for\nstarting distance", guide = guide_legend(reverse = TRUE), values = c(21, 19)) +
      #scale_color_jama(guide = "none")+ #, palette = 'light'
      scale_color_manual(guide = "none", values = col_) + #guide_legend(reverse = TRUE)
      scale_x_continuous(breaks = round(seq(-0.3, 0.4, by = 0.1), 1), , expand = c(0.04, 0.04)) +
      ylab("") +
      xlab("Standardised effect size of\nStringency Index\n[on flight initiation distance]") +
      labs(tag = 'a)')+
      # coord_cartesian(xlim = c(-.15, .15)) +
      # scale_x_continuous(breaks = round(seq(-.15, .15, by = 0.05),2)) +
      theme_bw() +
      theme(
          legend.position = "right",
          plot.tag = element_text(size = 7),
          legend.title = element_text(size = 7),
          legend.text = element_text(size = 6),
          # legend.spacing.y = unit(0.1, 'cm'),
          legend.key.height = unit(0.5, "line"),
          legend.margin = margin(0, 0, 0, 0),
          # legend.position=c(0.5,1.6),
          plot.title = element_text(color = "grey", size = 7),
          plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r = 1, unit = "pt"),
          panel.grid = element_blank(),
          panel.border = element_blank(),
          panel.background = element_blank(),
          axis.line = element_line(colour = ax_lines, size = 0.25),
          axis.line.y = element_blank(),
          axis.ticks.y = element_blank(),
          axis.ticks.x = element_line(colour = ax_lines, size = 0.25),
          # axis.text.x = element_text()
          axis.ticks.length = unit(1, "pt"),
          axis.text.x = element_text(, size = 6),
          axis.text.y = element_text(colour = "black", size = 7),
          axis.title = element_text(size = 7)
      )

  #if(save_plot==TRUE){
  #ggsave(here::here("Outputs/Fig_S6a_Stringency.png"), gs6a, width = 8, height = 6.5, unit = "cm", dpi = 600)
  #}

# b
load(here::here("Data/dat_est_Google_rev.Rdata"))
og[predictor %in% c("scale(parks_percent_change_from_baseline)"), predictor := "Google Mobility"]
ogo <- og[predictor %in% c("Google Mobility")]
ogo[, N:=as.numeric(sub('.*N = ', '', model))]
# add meta-analytical mean
  ogo_s = ogo[control_for_starting_distance == 'yes']
  met = summary(meta.summaries(d = ogo_s$estimate, se = ogo_s$sd, method = "fixed", weights = ogo_s$N))$summci
  ogo_met = data.table(predictor = "Period", estimate = met[2], lwr = met[1], upr = met[3], sd = NA, model = NA, control_for_starting_distance = "yes", Country = "Combined\n(metanalytical)", N = NA)

  ogo_sx = ogo[control_for_starting_distance == "no"]
  metx = summary(meta.summaries(d = ogo_sx$estimate, se = ogo_sx$sd, method = "fixed", weights = ogo_sx$N))$summci
  ogo_metx = data.table(predictor = "Period", estimate = metx[2], lwr = metx[1], upr = metx[3], sd = NA, model = NA, control_for_starting_distance = "no", Country = "Combined\n(metanalytical)", N = NA)
  
  ogo = rbind(ogo, ogo_met, ogo_metx)
    
ogo[, Country := factor(Country, levels = rev(c("Finland", "Poland", "Czechia", "Hungary", "Australia", "Combined\n(metanalytical)", "All\n(mixed model)")))]

# prepare for adding N
ogo[, N := as.character(N)]
ogo[control_for_starting_distance == "no" | is.na(N), N := ""]
ogo[, n_pos := .15]

width_ <- .5 # spacing between error bars
col_ = c("#357EBDFF", "#D43F3AFF", "#46B8DAFF", "#5CB85CFF", "#EEA236FF", "#9632B8FF", "#9632B8FF")[7:1] # "#D43F3AFF", "#B8B8B8FF" #show_col(col_)

gs6b = 
ggplot(ogo, aes(x = estimate, y = Country, col = Country, shape = control_for_starting_distance)) +
    geom_vline(xintercept = 0, color = "grey", linetype = "dotted") +
    geom_errorbarh(aes(xmin = lwr, xmax = upr), height = 0, position = ggstance::position_dodgev(width_)) +
    # geom_point(position = ggstance::position_dodgev(.6)) +
    geom_point(position = position_dodge(width = width_), bg = "white", size = 1.1) +
    # scale_color_viridis(discrete=TRUE, begin=0, end = 0.5)  +
    # scale_fill_viridis(discrete=TRUE, begin=0, end = 0.5) +
    # geom_text( aes(x = n_pos,label = N), vjust = 0, size = 1.75, position = ggstance::position_dodgev(width_))+ # 3 positions for 3 bars
    # annotate("text", x=log10(3), y=85, label= "Used", col = "grey30", size = 2.5)+
    geom_text( aes(x = n_pos,label = N), vjust = 1, size = 1.75, position = ggstance::position_dodgev(width_))+
    scale_shape_manual(name = "Controlled for\nstarting distance", guide = guide_legend(reverse = TRUE), values = c(21, 19)) +
    #scale_color_jama(guide = "none")+ #, palette = 'light'
    scale_color_manual(guide = "none", values = col_) + #guide_legend(reverse = TRUE)
    scale_x_continuous(breaks = round(seq(-0.3, 0.2, by = 0.1), 1)) +
    ylab("") +
    xlab("Standardised effect size of\nGoogle Mobility (human presence)\n[on flight initiation distance]") +
    labs(tag = 'b)')+
    # coord_cartesian(xlim = c(-.15, .15)) +
    # scale_x_continuous(breaks = round(seq(-.15, .15, by = 0.05),2)) +
    theme_bw() +
    theme(
        plot.tag = element_text(size = 7),
        legend.position = "right",
        legend.title = element_text(size = 7),
        legend.text = element_text(size = 6),
        # legend.spacing.y = unit(0.1, 'cm'),
        legend.key.height = unit(0.5, "line"),
        legend.margin = margin(0, 0, 0, 0),
        # legend.position=c(0.5,1.6),
        plot.title = element_text(color = "grey", size = 7),
        plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r = 1, unit = "pt"),
        panel.grid = element_blank(),
        panel.border = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = ax_lines, size = 0.25),
        axis.line.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.ticks.x = element_line(colour = ax_lines, size = 0.25),
        # axis.text.x = element_text()
        axis.ticks.length = unit(1, "pt"),
        axis.text.x = element_text(, size = 6),
        axis.text.y = element_text(colour = "black", size = 7),
        axis.title = element_text(size = 7)
    )
#if(save_plot==TRUE){
#ggsave(here::here("Outputs/Fig_S6b_Google_rev_width_CustomLocusZoom_v2.png"), gs6b, width = 8, height = 6.5, unit = "cm", dpi = 600)
#}

# c
load(here::here("Data/dat_est_numberOFhumans_rev.Rdata")) # load(here::here("Data/dat_est_humans_rev_no_2018-CZ.Rdata"))

oh[predictor %in% c("scale(Human)"), predictor := "# of humans"]
oho <- oh[predictor %in% c("# of humans")]
oho[, N := as.numeric(sub(".*N = ", "", model))]
# add meta-analytical mean
oho_s <- oho[control_for_starting_distance == "yes"]
met <- summary(meta.summaries(d = oho_s$estimate, se = oho_s$sd, method = "fixed", weights = oho_s$N))$summci
oho_met <- data.table(predictor = "# of humans", estimate = met[2], lwr = met[1], upr = met[3], sd = NA, model = NA, control_for_starting_distance = "yes", Country = "Combined\n(metanalytical)", N = NA)

oho_sx <- oho[control_for_starting_distance == "no"]
metx <- summary(meta.summaries(d = oho_sx$estimate, se = oho_sx$sd, method = "fixed", weights = oho_sx$N))$summci
oho_metx <- data.table(predictor = "# of humans", estimate = metx[2], lwr = metx[1], upr = metx[3], sd = NA, model = NA, control_for_starting_distance = "no", Country = "Combined\n(metanalytical)", N = NA)

oho_au = data.table(predictor = "# of humans", estimate = NA, lwr = NA, upr = NA, sd = NA, model = NA, control_for_starting_distance = c("no","yes"),  Country = "Australia", N = 0) # dummy for australia
oho <- rbind(oho, oho_met, oho_metx, oho_au)

oho[, Country := factor(Country, levels = rev(c("Finland", "Poland", "Czechia", "Hungary","Australia", "Combined\n(metanalytical)", "All\n(mixed model)")))]

# prepare for adding N
oho[, N := as.character(N)]
oho[control_for_starting_distance == "no" | is.na(N), N := ""]
oho[, n_pos := .1]

width_ <- .5 # spacing between error bars
col_ = c("#357EBDFF", "#D43F3AFF", "#46B8DAFF", "#5CB85CFF", "#EEA236FF", "#9632B8FF", "#9632B8FF")[7:1] #col_ <- c("#357EBDFF", "#D43F3AFF", "#46B8DAFF", "#5CB85CFF", "#9632B8FF", "#9632B8FF")[6:1] # "#D43F3AFF", "#B8B8B8FF" # show_col(col_)

gs6c <-
  ggplot(oho, aes(x = estimate, y = Country, col = Country, shape = control_for_starting_distance)) +
  geom_text(aes(x = n_pos, label = N), vjust = 1, size = 1.75, position = ggstance::position_dodgev(width_)) +
  geom_vline(xintercept = 0, color = "grey", linetype = "dotted") +
  geom_errorbarh(aes(xmin = lwr, xmax = upr), height = 0, position = ggstance::position_dodgev(width_)) +
  # geom_point(position = ggstance::position_dodgev(.6)) +
  geom_point(position = position_dodge(width = width_), bg = "white", size = 1.1) +
  # scale_color_viridis(discrete=TRUE, begin=0, end = 0.5)  +
  # scale_fill_viridis(discrete=TRUE, begin=0, end = 0.5) +
  # geom_text( aes(x = n_pos,label = N), vjust = 0, size = 1.75, position = ggstance::position_dodgev(width_))+ # 3 positions for 3 bars
  # annotate("text", x=log10(3), y=85, label= "Used", col = "grey30", size = 2.5)+
 
  scale_shape_manual(name = "Controlled for\nstarting distance", guide = guide_legend(reverse = TRUE), values = c(21, 19)) +
  # scale_color_jama(guide = "none")+ #, palette = 'light'
  scale_color_manual(guide = "none", values = col_) + # guide_legend(reverse = TRUE)
  scale_x_continuous(breaks = round(seq(-0.3, 0.1, by = 0.1), 1), limits = c(-0.3, 0.132)) +
  ylab("") +
  xlab("Standardised effect size of\n# of humans\n[on flight initiation distance]") +
  labs(tag = "c)") +
  # coord_cartesian(xlim = c(-.15, .15)) +
  # scale_x_continuous(breaks = round(seq(-.15, .15, by = 0.05),2)) +
  theme_bw() +
  theme(
    plot.tag = element_text(size = 7),
    legend.position = "right",
    legend.title = element_text(size = 7),
    legend.text = element_text(size = 6),
    # legend.spacing.y = unit(0.1, 'cm'),
    legend.key.height = unit(0.5, "line"),
    legend.margin = margin(0, 0, 0, 0),
    # legend.position=c(0.5,1.6),
    plot.title = element_text(color = "grey", size = 7),
    plot.margin = margin(b = 0.5, l = 0.5, t = 0.5, r = 1, unit = "pt"),
    panel.grid = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank(),
    axis.line = element_line(colour = ax_lines, size = 0.25),
    axis.line.y = element_blank(),
    axis.ticks.y = element_blank(),
    axis.ticks.x = element_line(colour = ax_lines, size = 0.25),
    # axis.text.x = element_text()
    axis.ticks.length = unit(1, "pt"),
    axis.text.x = element_text(, size = 6),
    axis.text.y = element_text(colour = "black", size = 7),
    axis.title = element_text(size = 7)
  )
#if (save_plot == TRUE) {
  #ggsave(here::here("Outputs/Fig_S6c_numberOFhumans.png"), gs6c, width = 8, height = 6.5, unit = "cm", #dpi = 600) # ggsave(here::here("Outputs/Fig_S6c_human_rev_width_CustomLocusZoom_v2_no2018CZ.png"), gs6c, width = 8, height = 6.5, unit = "cm", dpi = 600)
#}

# combine

  #gg_S6 <- ggarrange(
  #  gs6a, NULL, gs6b, widths = c(1,0.05,1),
  #  nrow = 1, common.legend = TRUE, legend = 'right'
  #)

gg_S6 <- gs6a + gs6b + gs6c +plot_layout(guides = "collect")

# adjust tag
gg_S6[[1]] <- gg_S6[[1]] + theme(
  #plot.margin = margin(r = 2, l = 2),
  plot.tag.position = c(.4, .98))

# Remove title from second subplot & adjust tag
gg_S6[[2]] <- gg_S6[[2]] + theme(
  plot.margin = margin(r = 2, l = 2),
  plot.tag.position = c(.035, .98),
  axis.text.y = element_blank(),
  axis.ticks.y = element_blank(),
  axis.title.y = element_blank()
  
)

# Remove title from third subplot & adjust tag
gg_S6[[3]] <- gg_S6[[3]] + theme(
   plot.tag.position = c(.035, .98),
  axis.text.y = element_blank(),
  axis.ticks.y = element_blank(),
  axis.title.y = element_blank()
)

if (save_plot == TRUE) {
  ggsave(here::here("Outputs/Fig_S6_rev_v2.png"), gg_S6, width = 8 * 2, height = 6.5, unit = "cm", dpi = 600)
}

gg_S6

Figure S6 | Changes in avian tolerance towards humans in response to (a) stringency of governmental measures, (b) Google Mobility and (c) number of humans during escape distance trial. The dots with horizontal lines represent estimated standardised effect size and their 95% confidence intervals, the numbers sample sizes. For the country-specific and “All”, the effect sizes and 95% confidence intervals come from the joint posterior distribution of 5000 simulated values generated by the sim function from the arm package (Gelman et al. 2022) using the mixed model outputs controlled for starting distance of the observer (filled circles) or not (empty circles; Table S4, S5 and S6). The models were further controlled for year, flock size (ln-transfomred), body size (ln-transformed), temperature (also a proxy for a day within the breeding season: rPearson = 0.48; Fig. S2), and time of a day, as well as for the non-independence of data points by fitting random intercepts of weekday, genus, species, species at a given day and year, country (in All - a global mixed model), site, and species within a site, while fitting, in case of “All” (global model on all countries) Stringency index, Google Mobility or number of humans as a random slope within country (i.e. allowing for different effect in each country). Fitting Stringency index or Google Mobility as random slope at other random intercepts produces similar results (Fig. S1b-c, Table S2b, S2c & S2d). The multicollinearity was small as correlations between predictors were weak (Fig. S2). For the “Combined”, the estimate and 95% confidence interval represent the meta-analytical mean based on the country estimates and their standard deviation (from the country-specific models), and sample size per country. Stringency index data were sourced from (Hale et al. 2021), Google Mobility from Google Mobility Reports and their analyses were restricted to data collected in the Period during the COVID-19 shutdowns. Number of humans was collected at the time of escape distance trial as number of humans within a 50 meter radius and includes data before and during COVID-19 shutdowns.

Table S4 | Escape distance in relation to Stringency index

out_FID_s$error_structure = out_FID_s$response = NULL
out_FID_s[model != "", model := c(
  "All countries", "All countries, without starting distance",
  "Finland", "Finland, without starting distance",
  "Poland", "Poland, without starting distance",
  "Czechia", "Czechia, without starting distance",
  "Hungary", "Hungary, without starting distance",
  "Australia", "Australia, without starting distance"
)]
setnames(out_FID_s, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
out_FID_s %>%
  kbl() %>%
  kable_paper("hover", full_width = F)
model N type effect estimate lower upper
All countries 3676 fixed (Intercept) -0.077 -0.334 0.181
fixed year 0.02 -0.03 0.067
fixed starting distance (ln)) 0.492 0.459 0.524
fixed flock size (ln) -0.003 -0.03 0.024
fixed body mass (ln) 0.022 -0.044 0.09
fixed time (sine of radians) -0.02 -0.062 0.022
fixed time (cosine of radians) -0.005 -0.039 0.031
fixed temperature -0.008 -0.047 0.033
fixed Stringency index 0.013 -0.153 0.178
random species within day & year (Intercept) 5% 3% 7%
random species within site (Intercept) 5% 3% 6%
random species (Intercept) 7% 6% 9%
random site (Intercept) 8% 7% 9%
random genus (Intercept) 4% 3% 4%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 2% -16% 16%
random Stringency index (slope) | country 2% -16% 16%
random Residual 67% 45% 97%
All countries, without starting distance 3676 fixed (Intercept) 0.051 -0.099 0.2
fixed year 0.083 0.028 0.14
fixed flock size (ln) 0.011 -0.019 0.04
fixed body mass (ln) 0.14 0.051 0.228
fixed time (sine of radians) 0.045 -0.001 0.093
fixed time (cosine of radians) 0.049 0.009 0.09
fixed temperature 0.005 -0.043 0.052
fixed Stringency index -0.007 -0.222 0.213
random species within day & year (Intercept) 6% 5% 8%
random species within site (Intercept) 5% 4% 7%
random species (Intercept) 9% 9% 10%
random site (Intercept) 13% 13% 14%
random genus (Intercept) 5% 5% 6%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 3% -9% 9%
random Stringency index (slope) | country 3% -9% 9%
random Residual 55% 45% 73%
Finland 354 fixed (Intercept) 0.032 -0.179 0.241
fixed year -0.106 -0.341 0.124
fixed starting distance (ln)) 0.189 0.085 0.288
fixed flock size (ln) -0.112 -0.212 -0.01
fixed body mass (ln) 0.174 0.016 0.341
fixed time (sine of radians) 0.061 -0.061 0.184
fixed time (cosine of radians) 0.012 -0.112 0.132
fixed temperature -0.084 -0.197 0.024
fixed Stringency index 0.155 -0.065 0.38
random species within site (Intercept) 12% 12% 13%
random species within day & year (Intercept) 3% 3% 3%
random site (Intercept) 12% 10% 15%
random species (Intercept) 0% 0% 1%
random genus (Intercept) 3% 2% 5%
random weekday (Intercept) 0% 0% 0%
random Residual 68% 64% 73%
Finland, without starting distance 354 fixed (Intercept) -0.01 -0.225 0.215
fixed year -0.064 -0.309 0.168
fixed flock size (ln) -0.106 -0.202 -0.003
fixed body mass (ln) 0.249 0.082 0.409
fixed time (sine of radians) 0.054 -0.072 0.182
fixed time (cosine of radians) 0.006 -0.12 0.135
fixed temperature -0.089 -0.205 0.03
fixed Stringency index 0.134 -0.094 0.368
random species within site (Intercept) 14% 14% 14%
random species within day & year (Intercept) 4% 3% 4%
random site (Intercept) 14% 11% 16%
random species (Intercept) 3% 2% 5%
random genus (Intercept) 1% 1% 2%
random weekday (Intercept) 0% 0% 0%
random Residual 63% 59% 69%
Poland 329 fixed (Intercept) 0.025 -0.209 0.251
fixed year -0.208 -0.478 0.064
fixed starting distance (ln)) 0.532 0.448 0.617
fixed flock size (ln) -0.031 -0.111 0.049
fixed body mass (ln) -0.082 -0.193 0.023
fixed time (sine of radians) 0.126 -0.132 0.395
fixed time (cosine of radians) -0.243 -0.513 0.015
fixed temperature -0.192 -0.308 -0.078
fixed Stringency index 0.04 -0.225 0.31
random species within day & year (Intercept) 7% 6% 6%
random species (Intercept) 9% 7% 10%
random genus (Intercept) 0% 0% 0%
random weekday (Intercept) 10% 5% 16%
random Residual 75% 67% 82%
Poland, without starting distance 329 fixed (Intercept) 0.017 -0.25 0.274
fixed year -0.337 -0.657 -0.025
fixed flock size (ln) 0.053 -0.045 0.146
fixed body mass (ln) -0.012 -0.168 0.137
fixed time (sine of radians) -0.034 -0.359 0.291
fixed time (cosine of radians) -0.074 -0.4 0.246
fixed temperature -0.183 -0.32 -0.047
fixed Stringency index 0.033 -0.284 0.348
random species within day & year (Intercept) 4% 4% 4%
random species (Intercept) 21% 17% 25%
random genus (Intercept) 0% 0% 0%
random weekday (Intercept) 5% 2% 8%
random Residual 69% 63% 77%
Czechia 1054 fixed (Intercept) 0.212 -0.013 0.434
fixed starting distance (ln)) 0.347 0.287 0.405
fixed flock size (ln) 0.005 -0.046 0.054
fixed body mass (ln) 0.181 0.018 0.344
fixed time (sine of radians) 0.063 -0.013 0.141
fixed time (cosine of radians) 0.002 -0.07 0.075
fixed temperature 0.024 -0.072 0.117
fixed Stringency index -0.051 -0.174 0.069
random species within site (Intercept) 4% 4% 4%
random species within day & year (Intercept) 2% 2% 2%
random species (Intercept) 14% 11% 17%
random genus (Intercept) 13% 10% 17%
random site (Intercept) 5% 4% 6%
random weekday (Intercept) 1% 0% 2%
random Residual 61% 53% 69%
Czechia, without starting distance 1054 fixed (Intercept) 0.211 -0.008 0.435
fixed starting distance (ln)) 0.347 0.287 0.406
fixed flock size (ln) 0.005 -0.047 0.056
fixed body mass (ln) 0.184 0.026 0.341
fixed time (sine of radians) 0.064 -0.011 0.139
fixed time (cosine of radians) 0.002 -0.069 0.071
fixed temperature 0.023 -0.071 0.12
fixed Stringency index -0.051 -0.172 0.068
random species within site (Intercept) 4% 4% 4%
random species within day & year (Intercept) 2% 2% 2%
random species (Intercept) 14% 12% 17%
random genus (Intercept) 13% 10% 17%
random site (Intercept) 5% 4% 6%
random weekday (Intercept) 1% 0% 2%
random Residual 61% 53% 69%
Hungary 874 fixed (Intercept) 0.07 -0.214 0.35
fixed year 0.161 0.049 0.276
fixed starting distance (ln)) 0.505 0.443 0.564
fixed flock size (ln) -0.001 -0.054 0.052
fixed body mass (ln) 0.007 -0.136 0.146
fixed time (sine of radians) -0.126 -0.193 -0.06
fixed time (cosine of radians) 0.025 -0.048 0.1
fixed temperature -0.018 -0.122 0.083
fixed Stringency index 0.031 -0.122 0.185
random species within day & year (Intercept) 2% 2% 2%
random species within site (Intercept) 0% 0% 0%
random species (Intercept) 1% 1% 1%
random genus (Intercept) 12% 8% 16%
random weekday (Intercept) 1% 0% 2%
random site (Intercept) 10% 6% 13%
random Residual 74% 65% 82%
Hungary, without starting distance 874 fixed (Intercept) 0.056 -0.414 0.534
fixed year 0.203 0.071 0.335
fixed flock size (ln) 0 -0.057 0.06
fixed body mass (ln) 0.299 0.076 0.519
fixed time (sine of radians) -0.147 -0.227 -0.071
fixed time (cosine of radians) 0.027 -0.058 0.113
fixed temperature -0.05 -0.172 0.073
fixed Stringency index -0.009 -0.178 0.163
random species within day & year (Intercept) 3% 3% 4%
random species within site (Intercept) 0% 0% 0%
random species (Intercept) 1% 1% 1%
random genus (Intercept) 27% 20% 32%
random weekday (Intercept) 1% 0% 2%
random site (Intercept) 17% 14% 19%
random Residual 51% 42% 61%
Australia 1065 fixed (Intercept) -0.052 -0.191 0.091
fixed year 0.036 -0.029 0.101
fixed starting distance (ln)) 0.496 0.444 0.549
fixed flock size (ln) 0.024 -0.024 0.073
fixed body mass (ln) -0.052 -0.149 0.041
fixed time (sine of radians) -0.036 -0.108 0.037
fixed time (cosine of radians) -0.052 -0.119 0.015
fixed temperature 0.033 -0.029 0.094
fixed Stringency index 0.058 -0.003 0.123
random species within day & year (Intercept) 6% 6% 6%
random species within site (Intercept) 12% 12% 12%
random species (Intercept) 11% 9% 13%
random genus (Intercept) 2% 2% 3%
random site (Intercept) 7% 5% 9%
random weekday (Intercept) 0% 0% 0%
random Residual 61% 57% 66%
Australia, without starting distance 1065 fixed (Intercept) -0.102 -0.285 0.086
fixed year 0.103 0.03 0.178
fixed flock size (ln) 0.056 0 0.11
fixed body mass (ln) 0.062 -0.065 0.185
fixed time (sine of radians) -0.01 -0.093 0.072
fixed time (cosine of radians) -0.02 -0.097 0.056
fixed temperature 0.04 -0.03 0.111
fixed Stringency index 0.091 0.017 0.165
random species within day & year (Intercept) 7% 7% 8%
random species within site (Intercept) 11% 11% 11%
random species (Intercept) 13% 11% 15%
random genus (Intercept) 7% 6% 8%
random site (Intercept) 8% 6% 10%
random weekday (Intercept) 0% 0% 0%
random Residual 54% 49% 59%

Table S5 | Escape distance in relations to Google Mobility

out_FID_g$R2_mar = out_FID_g$R2_con = out_FID_g$error_structure = out_FID_g$response = NULL
out_FID_g[model != "", model := c(
  "All countries", "All countries, without starting distance",
  "Finland", "Finland, without starting distance",
  "Poland", "Poland, without starting distance",
  "Czechia", "Czechia, without starting distance",
  "Hungary", "Hungary, without starting distance",
  "Australia", "Australia, without starting distance"
)]
setnames(out_FID_g, old = c('estimate_r','lwr_r','upr_r'), new =c('estimate','lower','upper' ))
out_FID_g %>%
  kbl() %>%
  kable_paper("hover", full_width = F)
model N type effect estimate lower upper
All countries 3644 fixed (Intercept) 0.026 -0.095 0.148
fixed year 0.018 -0.024 0.061
fixed starting distance (ln)) 0.499 0.467 0.531
fixed flock size (ln) -0.001 -0.028 0.026
fixed body mass (ln) 0.024 -0.043 0.092
fixed time (sine of radians) -0.009 -0.049 0.033
fixed time (cosine of radians) 0.011 -0.023 0.044
fixed temperature 0.022 -0.017 0.058
fixed Google Mobility -0.099 -0.229 0.032
random species within day & year (Intercept) 6% 5% 6%
random species within site (Intercept) 5% 4% 5%
random species (Intercept) 7% 7% 8%
random site (Intercept) 9% 8% 10%
random genus (Intercept) 3% 3% 4%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 1% -3% 4%
random country Google Mobility 1% -3% 4%
random Residual 68% 61% 78%
All countries, without starting distance 3644 fixed (Intercept) 0.099 -0.122 0.321
fixed year 0.07 0.022 0.118
fixed flock size (ln) 0.012 -0.016 0.041
fixed body mass (ln) 0.131 0.044 0.219
fixed time (sine of radians) 0.061 0.014 0.109
fixed time (cosine of radians) 0.075 0.037 0.112
fixed temperature 0.039 -0.005 0.082
fixed Google Mobility -0.118 -0.298 0.058
random species within day & year (Intercept) 7% 5% 9%
random species within site (Intercept) 6% 5% 7%
random species (Intercept) 11% 10% 12%
random site (Intercept) 12% 11% 13%
random genus (Intercept) 4% 5% 5%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 1% -13% 9%
random country Google Mobility 1% -13% 9%
random Residual 59% 46% 79%
Finland 322 fixed (Intercept) 0.026 -0.193 0.237
fixed year 0.13 -0.003 0.263
fixed starting distance (ln)) 0.197 0.09 0.305
fixed flock size (ln) -0.119 -0.221 -0.019
fixed body mass (ln) 0.24 0.084 0.393
fixed time (sine of radians) 0.131 -0.01 0.267
fixed time (cosine of radians) 0.041 -0.078 0.166
fixed temperature -0.005 -0.138 0.13
fixed Google Mobility -0.1 -0.245 0.04
random species within site (Intercept) 13% 12% 13%
random species within day & year (Intercept) 3% 2% 3%
random site (Intercept) 16% 13% 19%
random species (Intercept) 0% 0% 0%
random genus (Intercept) 2% 1% 4%
random weekday (Intercept) 0% 0% 0%
random Residual 66% 62% 71%
Finland, without starting distance 322 fixed (Intercept) -0.005 -0.232 0.215
fixed year 0.15 0.013 0.288
fixed flock size (ln) -0.114 -0.219 -0.008
fixed body mass (ln) 0.321 0.162 0.486
fixed time (sine of radians) 0.119 -0.029 0.263
fixed time (cosine of radians) 0.033 -0.093 0.158
fixed temperature -0.021 -0.149 0.118
fixed Google Mobility -0.087 -0.227 0.053
random species within site (Intercept) 15% 14% 15%
random species within day & year (Intercept) 3% 3% 3%
random site (Intercept) 17% 14% 20%
random species (Intercept) 0% 0% 0%
random genus (Intercept) 3% 1% 4%
random weekday (Intercept) 0% 0% 0%
random Residual 62% 57% 67%
Poland 329 fixed (Intercept) 0.034 -0.198 0.257
fixed year -0.249 -0.407 -0.09
fixed starting distance (ln)) 0.533 0.446 0.619
fixed flock size (ln) -0.032 -0.111 0.05
fixed body mass (ln) -0.083 -0.188 0.026
fixed time (sine of radians) 0.139 -0.129 0.398
fixed time (cosine of radians) -0.256 -0.514 0.019
fixed temperature -0.2 -0.302 -0.091
fixed Google Mobility 0 -0.136 0.139
random species within day & year (Intercept) 7% 6% 7%
random species (Intercept) 8% 7% 10%
random genus (Intercept) 0% 0% 0%
random weekday (Intercept) 10% 5% 16%
random Residual 75% 67% 82%
Poland, without starting distance 329 fixed (Intercept) 0.021 -0.234 0.274
fixed year -0.404 -0.582 -0.223
fixed flock size (ln) 0.052 -0.044 0.145
fixed body mass (ln) -0.011 -0.167 0.143
fixed time (sine of radians) -0.019 -0.334 0.29
fixed time (cosine of radians) -0.093 -0.4 0.214
fixed temperature -0.191 -0.313 -0.069
fixed Google Mobility 0.045 -0.116 0.201
random species within day & year (Intercept) 5% 4% 5%
random species (Intercept) 21% 17% 25%
random genus (Intercept) 0% 0% 0%
random weekday (Intercept) 5% 2% 8%
random Residual 70% 63% 77%
Czechia 1054 fixed (Intercept) 0.225 0.017 0.435
fixed starting distance (ln)) 0.344 0.284 0.402
fixed flock size (ln) 0.009 -0.042 0.061
fixed body mass (ln) 0.186 0.031 0.347
fixed time (sine of radians) 0.063 -0.005 0.132
fixed time (cosine of radians) 0.035 -0.021 0.092
fixed temperature 0.065 -0.008 0.134
fixed Google Mobility -0.09 -0.163 -0.019
random species within site (Intercept) 5% 5% 5%
random species within day & year (Intercept) 1% 0% 1%
random species (Intercept) 14% 11% 16%
random genus (Intercept) 14% 10% 17%
random site (Intercept) 6% 4% 7%
random weekday (Intercept) 0% 0% 0%
random Residual 61% 55% 69%
Czechia, without starting distance 1054 fixed (Intercept) 0.229 0.029 0.436
fixed starting distance (ln)) 0.343 0.285 0.403
fixed flock size (ln) 0.009 -0.041 0.059
fixed body mass (ln) 0.185 0.027 0.34
fixed time (sine of radians) 0.061 -0.009 0.13
fixed time (cosine of radians) 0.034 -0.021 0.092
fixed temperature 0.065 -0.005 0.134
fixed Google Mobility -0.091 -0.163 -0.018
random species within site (Intercept) 5% 5% 5%
random species within day & year (Intercept) 1% 0% 1%
random species (Intercept) 14% 11% 16%
random genus (Intercept) 14% 10% 17%
random site (Intercept) 6% 4% 7%
random weekday (Intercept) 0% 0% 0%
random Residual 61% 54% 69%
Hungary 874 fixed (Intercept) 0.073 -0.205 0.357
fixed year 0.168 0.056 0.28
fixed starting distance (ln)) 0.503 0.442 0.561
fixed flock size (ln) -0.001 -0.053 0.05
fixed body mass (ln) 0.002 -0.141 0.147
fixed time (sine of radians) -0.125 -0.191 -0.058
fixed time (cosine of radians) 0.017 -0.046 0.081
fixed temperature -0.032 -0.111 0.045
fixed Google Mobility -0.029 -0.134 0.078
random species within day & year (Intercept) 2% 2% 2%
random species within site (Intercept) 0% 0% 0%
random species (Intercept) 1% 1% 1%
random genus (Intercept) 12% 8% 16%
random weekday (Intercept) 1% 0% 2%
random site (Intercept) 9% 5% 13%
random Residual 74% 65% 83%
Hungary, without starting distance 874 fixed (Intercept) 0.06 -0.396 0.549
fixed year 0.315 0.187 0.445
fixed flock size (ln) -0.005 -0.064 0.054
fixed body mass (ln) 0.285 0.064 0.51
fixed time (sine of radians) -0.166 -0.243 -0.09
fixed time (cosine of radians) 0.034 -0.039 0.107
fixed temperature -0.048 -0.143 0.048
fixed Google Mobility -0.146 -0.27 -0.02
random species within day & year (Intercept) 2% 2% 2%
random species within site (Intercept) 1% 1% 1%
random species (Intercept) 1% 1% 2%
random genus (Intercept) 27% 19% 32%
random weekday (Intercept) 2% 1% 3%
random site (Intercept) 16% 13% 19%
random Residual 52% 42% 63%
Australia 1065 fixed (Intercept) -0.054 -0.197 0.088
fixed year 0.029 -0.036 0.092
fixed starting distance (ln)) 0.5 0.447 0.552
fixed flock size (ln) 0.024 -0.025 0.074
fixed body mass (ln) -0.051 -0.145 0.043
fixed time (sine of radians) -0.045 -0.115 0.029
fixed time (cosine of radians) -0.044 -0.112 0.026
fixed temperature 0.019 -0.039 0.078
fixed Google Mobility -0.036 -0.092 0.02
random species within day & year (Intercept) 6% 6% 6%
random species within site (Intercept) 12% 12% 12%
random species (Intercept) 11% 9% 13%
random genus (Intercept) 2% 2% 2%
random site (Intercept) 8% 6% 10%
random weekday (Intercept) 0% 0% 0%
random Residual 61% 56% 65%
Australia, without starting distance 1065 fixed (Intercept) -0.102 -0.302 0.089
fixed year 0.087 0.012 0.16
fixed flock size (ln) 0.054 -0.001 0.109
fixed body mass (ln) 0.067 -0.058 0.188
fixed time (sine of radians) -0.027 -0.11 0.055
fixed time (cosine of radians) -0.018 -0.097 0.06
fixed temperature 0.01 -0.058 0.079
fixed Google Mobility -0.026 -0.094 0.038
random species within day & year (Intercept) 7% 7% 7%
random species within site (Intercept) 11% 11% 11%
random species (Intercept) 13% 11% 15%
random genus (Intercept) 6% 5% 8%
random site (Intercept) 10% 8% 12%
random weekday (Intercept) 0% 0% 0%
random Residual 52% 48% 57%

Table S6 | Escape distance in relation to # of humans

out_FID_h$R2_mar <- out_FID_h$R2_con <- out_FID_h$error_structure <- out_FID_h$response <- NULL
out_FID_h[model != "", model := c(
  "All countries", "All countries, without starting distance",
  "Finland", "Finland, without starting distance",
  "Poland", "Poland, without starting distance",
  "Czechia", "Czechia, without starting distance",
  "Hungary", "Hungary, without starting distance"
)]
setnames(out_FID_h, old = c("estimate_r", "lwr_r", "upr_r"), new = c("estimate", "lower", "upper"))
out_FID_h %>%
  kbl() %>%
  kable_paper("hover", full_width = F)
model N type effect estimate lower upper
All countries 3504 fixed (Intercept) 0.154 -0.181 0.495
fixed starting distance (ln)) 0.466 0.432 0.5
fixed flock size (ln) -0.021 -0.048 0.005
fixed body mass (ln) 0.149 0.038 0.259
fixed time (sine of radians) 0.022 -0.016 0.06
fixed time (cosine of radians) -0.008 -0.041 0.024
fixed temperature -0.025 -0.064 0.012
fixed # of humans present -0.045 -0.08 -0.009
random species within day & year (Intercept) 8% 6% 8%
random species within site (Intercept) 3% 2% 3%
random site (Intercept) 5% 4% 5%
random species (Intercept) 4% 4% 4%
random genus (Intercept) 14% 11% 13%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 0% -1% 12%
random # of humans (slope) | country 0% -1% 12%
random Year (Intercept) 5% 3% 5%
random Residual 61% 42% 68%
All countries, without starting distance 3504 fixed (Intercept) 0.3 -0.023 0.644
fixed flock size (ln) -0.004 -0.032 0.024
fixed body mass (ln) 0.286 0.148 0.416
fixed time (sine of radians) 0.038 -0.002 0.08
fixed time (cosine of radians) 0.009 -0.028 0.045
fixed temperature -0.024 -0.066 0.017
fixed # of humans present -0.048 -0.119 0.024
random species within day & year (Intercept) 7% 6% 8%
random species within site (Intercept) 2% 2% 3%
random site (Intercept) 13% 12% 13%
random species (Intercept) 4% 4% 4%
random genus (Intercept) 17% 14% 19%
random weekday (Intercept) 0% 0% 0%
random country (Intercept) 0% -1% 4%
random # of humans (slope) | country 0% -1% 4%
random Year (Intercept) 6% 5% 7%
random Residual 50% 41% 57%
Finland 761 fixed (Intercept) -0.021 -0.218 0.184
fixed year -0.101 -0.179 -0.019
fixed starting distance (ln)) 0.281 0.217 0.35
fixed flock size (ln) -0.063 -0.127 0.001
fixed body mass (ln) 0.137 -0.002 0.277
fixed time (sine of radians) 0.095 0.017 0.172
fixed time (cosine of radians) -0.047 -0.117 0.025
fixed temperature -0.173 -0.259 -0.089
fixed # of humans present -0.101 -0.163 -0.041
random species within day & year (Intercept) 13% 13% 13%
random species within site (Intercept) 5% 5% 5%
random site (Intercept) 7% 6% 8%
random species (Intercept) 3% 2% 5%
random genus (Intercept) 3% 2% 5%
random weekday (Intercept) 2% 1% 3%
random Residual 67% 61% 72%
Finland, without starting distance 761 fixed (Intercept) -0.088 -0.331 0.152
fixed year -0.04 -0.121 0.041
fixed flock size (ln) -0.028 -0.094 0.035
fixed body mass (ln) 0.255 0.091 0.419
fixed time (sine of radians) 0.101 0.022 0.181
fixed time (cosine of radians) -0.062 -0.139 0.012
fixed temperature -0.178 -0.264 -0.094
fixed # of humans present -0.12 -0.186 -0.058
random species within day & year (Intercept) 12% 12% 13%
random species within site (Intercept) 4% 4% 4%
random site (Intercept) 9% 7% 10%
random species (Intercept) 6% 4% 8%
random genus (Intercept) 3% 2% 4%
random weekday (Intercept) 3% 1% 5%
random Residual 63% 57% 69%
Poland 263 fixed (Intercept) 0.082 -0.069 0.236
fixed starting distance (ln)) 0.58 0.481 0.677
fixed flock size (ln) -0.042 -0.139 0.055
fixed body mass (ln) -0.169 -0.306 -0.035
fixed time (sine of radians) -0.111 -0.304 0.076
fixed time (cosine of radians) 0.04 -0.104 0.194
fixed temperature -0.071 -0.193 0.058
fixed # of humans present -0.034 -0.166 0.096
random species within day & year (Intercept) 18% 17% 18%
random species (Intercept) 12% 9% 14%
random genus (Intercept) 0% 0% 0%
random weekday (Intercept) 0% 0% 0%
random Residual 71% 68% 74%
Poland, without starting distance 263 fixed (Intercept) 0.273 -0.012 0.534
fixed flock size (ln) 0.018 -0.096 0.133
fixed body mass (ln) -0.024 -0.251 0.201
fixed time (sine of radians) -0.097 -0.316 0.13
fixed time (cosine of radians) 0.009 -0.167 0.182
fixed temperature -0.103 -0.253 0.046
fixed # of humans present -0.027 -0.182 0.133
random species within day & year (Intercept) 17% 16% 17%
random species (Intercept) 39% 32% 44%
random genus (Intercept) 0% 0% 0%
random weekday (Intercept) 0% 0% 0%
random Residual 44% 40% 50%
Czechia 1024 fixed (Intercept) 0.24 0.045 0.433
fixed year 0.183 0.09 0.278
fixed starting distance (ln)) 0.336 0.259 0.412
fixed flock size (ln) -0.002 -0.048 0.044
fixed body mass (ln) 0.2 0.045 0.361
fixed time (sine of radians) 0.032 -0.089 0.157
fixed time (cosine of radians) -0.055 -0.177 0.065
fixed temperature 0.073 0.005 0.143
fixed # of humans present -0.046 -0.109 0.018
random species within site (Intercept) 2% 2% 2%
random species within day & year (Intercept) 4% 4% 4%
random species (Intercept) 16% 13% 19%
random site (Intercept) 5% 4% 6%
random genus (Intercept) 12% 9% 15%
random weekday (Intercept) 0% 0% 0%
random Residual 61% 54% 68%
Czechia, without starting distance 1024 fixed (Intercept) 0.241 0.044 0.431
fixed year 0.184 0.094 0.277
fixed starting distance (ln)) 0.335 0.26 0.412
fixed flock size (ln) -0.002 -0.05 0.044
fixed body mass (ln) 0.2 0.046 0.356
fixed time (sine of radians) 0.032 -0.088 0.154
fixed time (cosine of radians) -0.053 -0.177 0.067
fixed temperature 0.073 0.005 0.14
fixed # of humans present -0.046 -0.111 0.019
random species within site (Intercept) 2% 2% 2%
random species within day & year (Intercept) 4% 4% 4%
random species (Intercept) 16% 13% 19%
random site (Intercept) 5% 4% 6%
random genus (Intercept) 12% 9% 15%
random weekday (Intercept) 0% 0% 0%
random Residual 61% 54% 68%
Hungary 1456 fixed (Intercept) 0.087 -0.117 0.301
fixed year -0.066 -0.124 -0.007
fixed starting distance (ln)) 0.491 0.444 0.54
fixed flock size (ln) -0.02 -0.062 0.021
fixed body mass (ln) -0.061 -0.188 0.063
fixed time (sine of radians) -0.068 -0.124 -0.011
fixed time (cosine of radians) 0.028 -0.019 0.075
fixed temperature 0.022 -0.035 0.079
fixed # of humans present 0.006 -0.035 0.046
random species within day & year (Intercept) 9% 8% 9%
random species within site (Intercept) 0% 0% 0%
random species (Intercept) 2% 2% 3%
random genus (Intercept) 8% 5% 11%
random site (Intercept) 4% 1% 7%
random weekday (Intercept) 2% 1% 3%
random Residual 76% 67% 82%
Hungary, without starting distance 1456 fixed (Intercept) 0.068 -0.272 0.402
fixed year -0.062 -0.132 0.011
fixed flock size (ln) -0.021 -0.067 0.025
fixed body mass (ln) 0.197 0.009 0.393
fixed time (sine of radians) -0.099 -0.164 -0.033
fixed time (cosine of radians) 0.038 -0.015 0.093
fixed temperature 0.029 -0.039 0.097
fixed # of humans present 0.014 -0.032 0.06
random species within day & year (Intercept) 10% 9% 11%
random species within site (Intercept) 0% 0% 0%
random species (Intercept) 1% 1% 2%
random genus (Intercept) 20% 15% 25%
random site (Intercept) 9% 4% 14%
random weekday (Intercept) 2% 1% 3%
random Residual 58% 47% 69%

Testing for phylo-signal in residuals

Example code. Don’t run, as it takes too long. To make the Table S7, load the saved mcmc outputs instead.

# read trees 
trees = read.tree("Data/trees.tre")

# get residuals
# period
ms <- lmer(scale(log(FID)) ~
  scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Covid) +
  (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(Covid) | Country) + (scale(Covid) | IDLocality) + (1 | sp_loc),
data = d, REML = FALSE,
control <- lmerControl(
  optimizer = "optimx", optCtrl = list(method = "nlminb")
)
)
d[, res_period := resid(ms)]
# stringency
m01a <- lmer(scale(log(FID)) ~
  scale(Year) +
  scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(StringencyIndex) +
  (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(StringencyIndex) | Country) + (1 | IDLocality) + (1 | sp_loc),
data = s, REML = FALSE
)
s[, res := resid(m01a)]
# google
mg01a = lmer(scale(log(FID)) ~
  scale(Year) +
  scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(parks_percent_change_from_baseline) +
  (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) + (scale(parks_percent_change_from_baseline) | Country) + (1 | IDLocality) + (1 | sp_loc),
data = ss, REML = FALSE
)
ss[, res := resid(mg01a)]

# # of humans
mhs <- lmer(scale(log(FID)) ~
  scale(log(SD)) +
  scale(log(FlockSize)) +
  scale(log(BodyMass)) +
  scale(sin(rad)) + scale(cos(rad)) +
  # scale(Day)+
  scale(Temp) +
  scale(Human) +
  (1 | Year) + (1 | weekday) + (1 | genus) + (1 | Species) + (1 | sp_day_year) +
  (scale(Human) | Country) + (1 | IDLocality) + (1 | sp_loc),
data = dh, REML = FALSE
)
dh[, res := resid(mhs)]

# MCC tree and covariance matrix
namesd <- d %>% distinct(Species)
row.names(namesd) <- namesd$Species
namecheck_fidd <- name.check(trees[[1]], namesd)
trees_fidd <- lapply(trees, drop.tip, namecheck_fidd$tree_not_data)
class(trees_fidd) <- "multiPhylo"
length(trees_fidd[[1]]$tip.label)
tree_fidd <- maxCladeCred(trees_fidd)
tree_fidd$node.label <- NULL
inv.phylo_d <- inverseA(tree_fidd, nodes = "ALL", scale = TRUE)
phyloresd <- solve(inv.phylo_d$Ainv)
rownames(phyloresd) <- rownames(inv.phylo_d$Ainv)

namess <- s %>% distinct(Species)
row.names(namess) <- namess$Species
namecheck_fids <- name.check(trees[[1]], namess)
trees_fids <- lapply(trees, drop.tip, namecheck_fids$tree_not_data)
class(trees_fids) <- "multiPhylo"
length(trees_fids[[1]]$tip.label)
tree_fids <- maxCladeCred(trees_fids)
tree_fids$node.label <- NULL
inv.phylo_s <- inverseA(tree_fids, nodes = "ALL", scale = TRUE)
phyloress <- solve(inv.phylo_s$Ainv)
rownames(phyloress) <- rownames(inv.phylo_s$Ainv)

namesss <- ss %>% distinct(Species)
row.names(namesss) <- namesss$Species
namecheck_fidss <- name.check(trees[[1]], namesss)
trees_fidss <- lapply(trees, drop.tip, namecheck_fidss$tree_not_data)
class(trees_fidss) <- "multiPhylo"
length(trees_fidss[[1]]$tip.label)
tree_fidss <- maxCladeCred(trees_fidss)
tree_fidss$node.label <- NULL
inv.phylo_ss <- inverseA(tree_fidss, nodes = "ALL", scale = TRUE)
phyloresss <- solve(inv.phylo_ss$Ainv)
rownames(phyloresss) <- rownames(inv.phylo_ss$Ainv)

namesdh <- dh %>% distinct(Species)
row.names(namesdh) <- namesdh$Species
namecheck_fiddh <- name.check(trees[[1]], namesdh)
trees_fiddh <- lapply(trees, drop.tip, namecheck_fiddh$tree_not_data)
class(trees_fiddh) <- "multiPhylo"
length(trees_fiddh[[1]]$tip.label)
tree_fiddh <- maxCladeCred(trees_fiddh)
tree_fiddh$node.label <- NULL
inv.phylo_dh <- inverseA(tree_fiddh, nodes = "ALL", scale = TRUE)
phyloresdh <- solve(inv.phylo_dh$Ainv)
rownames(phyloresdh) <- rownames(inv.phylo_dh$Ainv)

# brms

# period - no - need to run (takes time), if you load the above DAT_brms.Rdata
# without phylo
priors <- get_prior(res_period ~ 0 + Intercept + (1 | Species), data = d) #
mP_no = brm(
  form = res_period ~ 0 + Intercept + (1 | Species),
  data = d,
  cores = 2,
  chains = 5,
  control = list(adapt_delta = 0.99),
  iter = 5000,
  thin = 5,
  sample_prior = "yes",
  save_pars = save_pars(all = TRUE),
  prior = priors,
  seed = 5
)
plot(mP_no, ask = FALSE)
pp_check(mP_no, ndraws = 100)
mcmc_plot(mP_no, type = "acf")
summary(mP_no)
# with phylo
priors <- get_prior(res_period ~ 0 + Intercept + (1 | Species) + (1 | gr(scinam, cov = A)), data = d, data2 = list(A = phyloresd))
mP_yes = brm(
  form = res_period ~ 0 + Intercept + (1 | Species) + (1 | gr(scinam, cov = A)),
  data = d,
  data2 = list(A = phyloresd),
  cores = 2,
  chains = 5,
  control = list(adapt_delta = 0.99),
  iter = 5000,
  thin = 5,
  sample_prior = "yes",
  save_pars = save_pars(all = TRUE),
  prior = priors,
  seed = 5
)
plot(mP_yes, ask = FALSE)
pp_check(mP_yes, ndraws = 100)
# pp_check(m_yes, type = "scatter_avg_grouped", group = "Species") +  geom_abline(intercept = 0, slope = 1 , color = "red", lty = 2)
mcmc_plot(mP_yes, type = "acf")
summary(mP_yes)

# lambda
hypothesis(mP_yes, "sd_scinam__Intercept^2 / (sd_scinam__Intercept^2 + sd_Species__Intercept^2) = 0", class = NULL)
hypothesis(mP_yes, "sd_scinam__Intercept^2 / (sd_scinam__Intercept^2 + sd_Species__Intercept^2 + sigma^2) = 0", class = NULL)


v_sc <- (VarCorr(mP_yes, summary = FALSE)$scinam$sd)^2
v_sp <- (VarCorr(mP_yes, summary = FALSE)$Species$sd)^2
v_r <- (VarCorr(mP_yes, summary = FALSE)$residual$sd)^2
summary(as.mcmc(v_sc / (v_sc + v_sp + v_r)))

# compare period models
# 1. LOOic
loo(mP_yes)
loo(mP_no)

# 2. Bayes factor
bayes_factor(mP_no, mP_yes)

# 3. Poterior probability
post_prob(mP_yes, mP_no)

# stringency index  - no - need to run (takes time), if you load the above DAT_brms.Rdata
# without phylo
priors <- get_prior(res ~ 0 + Intercept + (1 | Species), data = s) #
m_no = brm(
  form = res ~ 0 + Intercept + (1 | Species),
  data = s,
  cores = 2,
  chains = 5,
  control = list(adapt_delta = 0.99),
  iter = 5000,
  thin = 5,
  sample_prior = "yes",
  save_pars = save_pars(all = TRUE),
  prior = priors,
  seed = 5
)
plot(m_no, ask = FALSE)
pp_check(m_no, ndraws = 100)
mcmc_plot(m_no, type = "acf")
summary(m_no)
# with phylo
priors <- get_prior(res ~ 0 + Intercept + (1 | Species) + (1 | gr(scinam, cov = A)), data = s, data2 = list(A = phyloress))
m_yes = brm(
  form = res ~ 0 + Intercept + (1 | Species) + (1 | gr(scinam, cov = A)),
  data = s,
  data2 = list(A = phyloress),
  cores = 2,
  chains = 5,
  control = list(adapt_delta = 0.99),
  iter = 5000,
  thin = 5,
  sample_prior = "yes",
  save_pars = save_pars(all = TRUE),
  prior = priors,
  seed = 5
)
plot(m_yes, ask = FALSE)
pp_check(m_yes, ndraws = 100)
# pp_check(m_yes, type = "scatter_avg_grouped", group = "Species") +  geom_abline(intercept = 0, slope = 1 , color = "red", lty = 2)
mcmc_plot(m_yes, type = "acf")
summary(m_yes)

# lambda
hypothesis(m_yes, "sd_scinam__Intercept^2 / (sd_scinam__Intercept^2 + sd_Species__Intercept^2) = 0", class = NULL) # lambda
hypothesis(m_yes, "sd_scinam__Intercept^2 / (sd_scinam__Intercept^2 + sd_Species__Intercept^2 + sigma^2) = 0", class = NULL)

v_sc <- (VarCorr(m_yes, summary = FALSE)$scinam$sd)^2
v_sp <- (VarCorr(m_yes, summary = FALSE)$Species$sd)^2
v_r <- (VarCorr(m_yes, summary = FALSE)$residual$sd)^2
summary(as.mcmc(v_sc / (v_sc + v_sp + v_r)))
Mode(as.mcmc(v_sc / (v_sc + v_sp + v_r)))

# compare stringency models
# 1. LOOic
loo(m_yes)
loo(m_no)

# 2. Bayes factor
bayes_factor(m_no, m_yes)

# 3. Poterior probability
post_prob(m_yes, m_no)

# Google Mobility  - no - need to run (takes time), if you load the above DAT_brms.Rdata
# without phylo
priors <- get_prior(res ~ 0 + Intercept + (1 | Species), data = ss) #
mG_no = brm(
  form = res ~ 0 + Intercept + (1 | Species),
  data = ss,
  cores = 2,
  chains = 5,
  control = list(adapt_delta = 0.99),
  iter = 5000,
  thin = 5,
  sample_prior = "yes",
  save_pars = save_pars(all = TRUE),
  prior = priors,
  seed = 5
)
plot(mG_no, ask = FALSE)
pp_check(mG_no, ndraws = 100)
mcmc_plot(mG_no, type = "acf")
summary(mG_no)
# with phylo
priors <- get_prior(res ~ 0 + Intercept + (1 | Species) + (1 | gr(scinam, cov = A)), data = ss, data2 = list(A = phyloress))
mG_yes = brm(
  form = res ~ 0 + Intercept + (1 | Species) + (1 | gr(scinam, cov = A)),
  data = ss,
  data2 = list(A = phyloress),
  cores = 2,
  chains = 5,
  control = list(adapt_delta = 0.99),
  iter = 5000,
  thin = 5,
  sample_prior = "yes",
  save_pars = save_pars(all = TRUE),
  prior = priors,
  seed = 5
)
plot(mG_yes, ask = FALSE)
pp_check(mG_yes, ndraws = 100)
# pp_check(m_yes, type = "scatter_avg_grouped", group = "Species") +  geom_abline(intercept = 0, slope = 1 , color = "red", lty = 2)
mcmc_plot(mG_yes, type = "acf")
summary(mG_yes)

# lambda
hypothesis(mG_yes, "sd_scinam__Intercept^2 / (sd_scinam__Intercept^2 + sd_Species__Intercept^2) = 0", class = NULL) # lambda
hypothesis(mG_yes, "sd_scinam__Intercept^2 / (sd_scinam__Intercept^2 + sd_Species__Intercept^2 + sigma^2) = 0", class = NULL)

v_sc <- (VarCorr(mG_yes, summary = FALSE)$scinam$sd)^2
v_sp <- (VarCorr(mG_yes, summary = FALSE)$Species$sd)^2
v_r <- (VarCorr(mG_yes, summary = FALSE)$residual$sd)^2
summary(as.mcmc(v_sc / (v_sc + v_sp + v_r)))
Mode(as.mcmc(v_sc / (v_sc + v_sp + v_r)))

# compare stringency models
# 1. LOOic
loo(mG_yes)
loo(mG_no)

# 2. Bayes factor
bayes_factor(mG_no, mG_yes)

# 3. Poterior probability
post_prob(mG_yes, mG_no)

# # of humans  - no - need to run (takes time), if you load the above DAT_brms.Rdata
# without phylo
priors <- get_prior(res ~ 0 + Intercept + (1 | Species), data = dh) #
mH_no = brm(
  form = res ~ 0 + Intercept + (1 | Species),
  data = dh,
  cores = 2,
  chains = 5,
  control = list(adapt_delta = 0.99),
  iter = 5000,
  thin = 5,
  sample_prior = "yes",
  save_pars = save_pars(all = TRUE),
  prior = priors,
  seed = 5
)
plot(mH_no, ask = FALSE)
pp_check(mH_no, ndraws = 100)
mcmc_plot(mH_no, type = "acf")
summary(mH_no)

# with phylo
priors <- get_prior(res ~ 0 + Intercept + (1 | Species) + (1 | gr(scinam, cov = A)), data = dh, data2 = list(A = phyloresdh))
mH_yes = brm(
  form = res ~ 0 + Intercept + (1 | Species) + (1 | gr(scinam, cov = A)),
  data = dh,
  data2 = list(A = phyloresdh),
  cores = 2,
  chains = 5,
  control = list(adapt_delta = 0.99),
  iter = 5000,
  thin = 5,
  sample_prior = "yes",
  save_pars = save_pars(all = TRUE),
  prior = priors,
  seed = 5
)
plot(mH_yes, ask = FALSE)
pp_check(mH_yes, ndraws = 100)
# pp_check(m_yes, type = "scatter_avg_grouped", group = "Species") +  geom_abline(intercept = 0, slope = 1 , color = "red", lty = 2)
mcmc_plot(mH_yes, type = "acf")
summary(mH_yes)

# lambda
hypothesis(mH_yes, "sd_scinam__Intercept^2 / (sd_scinam__Intercept^2 + sd_Species__Intercept^2) = 0", class = NULL) # lambda
hypothesis(mH_yes, "sd_scinam__Intercept^2 / (sd_scinam__Intercept^2 + sd_Species__Intercept^2 + sigma^2) = 0", class = NULL)

v_sc <- (VarCorr(mH_yes, summary = FALSE)$scinam$sd)^2
v_sp <- (VarCorr(mH_yes, summary = FALSE)$Species$sd)^2
v_r <- (VarCorr(mH_yes, summary = FALSE)$residual$sd)^2
summary(as.mcmc(v_sc / (v_sc + v_sp + v_r)))
Mode(as.mcmc(v_sc / (v_sc + v_sp + v_r)))

# compare stringency models
# 1. LOOic
loo(mH_yes)
loo(mH_no)

# 2. Bayes factor
bayes_factor(mH_no, mH_yes)

# 3. Poterior probability
post_prob(mH_yes, mH_no)

# export models
save(file = 'Data/rev_DAT_brms_P.Rdata', mP_no, mP_yes)
save(file = 'Data/rev_DAT_brms_S.Rdata', m_no, m_yes)
save(file = 'Data/rev_DAT_brms_G.Rdata', mG_no, mG_yes)
save(file = 'Data/rev_DAT_brms_H.Rdata', mH_no, mH_yes)

load(here::here("Data/rev_DAT_brms_P.Rdata"))
load(here::here("Data/rev_DAT_brms_S.Rdata"))
load(here::here("Data/rev_DAT_brms_G.Rdata"))
load(here::here("Data/rev_DAT_brms_H.Rdata"))

v_sc <- (VarCorr(mP_yes, summary = FALSE)$scinam$sd)^2
v_sp <- (VarCorr(mP_yes, summary = FALSE)$Species$sd)^2
v_r <- (VarCorr(mP_yes, summary = FALSE)$residual$sd)^2

s_v_sc <- (VarCorr(m_yes, summary = FALSE)$scinam$sd)^2
s_v_sp <- (VarCorr(m_yes, summary = FALSE)$Species$sd)^2
s_v_r <- (VarCorr(m_yes, summary = FALSE)$residual$sd)^2

g_v_sc <- (VarCorr(mG_yes, summary = FALSE)$scinam$sd)^2
g_v_sp <- (VarCorr(mG_yes, summary = FALSE)$Species$sd)^2
g_v_r <- (VarCorr(mG_yes, summary = FALSE)$residual$sd)^2

h_v_sc <- (VarCorr(mH_yes, summary = FALSE)$scinam$sd)^2
h_v_sp <- (VarCorr(mH_yes, summary = FALSE)$Species$sd)^2
h_v_r <- (VarCorr(mH_yes, summary = FALSE)$residual$sd)^2
# summary(as.mcmc(v_sc / (v_sc + v_sp + v_r)))

ts5 <- data.table(
  "Residuals\nfrom" = c(
    "Table S2a - model 01a (Period)",
    "Table S2b - model 01a (Stringency index)",
    "Table S2c - model 01a (Google Mobility)",
    "Table S2d - model 01a (# of humans)"
  ),
  "Variance explained by phylogeny\n(95%CI)" = c(
    paste0(paste(round(quantile(as.mcmc(v_sc / (v_sc + v_sp + v_r)), probs = c(0.025, 0.975)) * 100, 2), collapse = "-"), "%"),
    paste0(paste(round(quantile(as.mcmc(s_v_sc / (s_v_sc + s_v_sp + s_v_r)), probs = c(0.025, 0.975)) * 100, 2), collapse = "-"), "%"),
    paste0(paste(round(quantile(as.mcmc(g_v_sc / (g_v_sc + g_v_sp + g_v_r)), probs = c(0.025, 0.975)) * 100, 2), collapse = "-"), "%"),
    paste0(paste(round(quantile(as.mcmc(h_v_sc / (h_v_sc + h_v_sp + h_v_r)), probs = c(0.025, 0.975)) * 100, 2), collapse = "-"), "%")
  ),
  "Bayes\nfactor" = c(
    round(bayes_factor(mP_no, mP_yes)$bf),
    round(bayes_factor(m_no, m_yes)$bf),
    round(bayes_factor(mG_no, mG_yes)$bf),
    round(bayes_factor(mH_no, mH_yes)$bf)
  ),
  "Probability of non-phylogenetic model" = c(
    round(post_prob(mP_yes, mP_no)[2], 2),
    round(post_prob(m_yes, m_no)[2], 2),
    round(post_prob(mG_yes, mG_no)[2], 2),
    round(post_prob(mH_yes, mH_no)[2], 2)
  )
)
#save(file = "Data/T_S7.Rdata", ts5)
fwrite(file = "Data/T_S7.csv", ts5)

Table S7 | Are residuals confounded by phylogeny? Comparison of models on residulas without and with control for phylogeny.

ts5 = fread(here::here('Outputs/T_S7.csv'))
ts5 %>%
  kbl(align=c('l', 'r', 'r','r')) %>%
  kable_paper("hover", full_width = F)
Residuals from Variance explained by phylogeny (95%CI) Bayes factor Probability of non-phylogenetic model
Table S2a - model 01a (Period) 0-0.19% 461 0.99
Table S2b - model 01a (stringency index) 0-0.38% 54 0.99
Table S2c - model 01a (Google Mobility) 0-0.36% 153 0.99
Table S2d - model 01a (# of humans) 0-0.56% 138 0.99

Testing whether residuals of the original a-models from Table S2a, S2b and S2c are confounded by phylogeny. Variance explained by phylogeny (95%CI) represents percentage of variance explained by phylogeny in an intercept only model fitted to residuals of the original models in STAN (Stan Development Team 2022) using ‘brm’ function from ‘brms’ R-package (Bürkner 2017, Bürkner 2018) with phylogeny and species as random effects. Bayes factor in favour of model without phylogeny and probability of non-phylogenetic model in comparison to a model with phylogeny. The Gelman-Rubin diagnostics was 1 for all models, indicating model convergence (Brooks & Gelman 1998). Note that for all cases, the model without phylogeny fits residuals better than a model with phylogeny, which justifies our use of simple original models, not controlled for phylogeny (Table S2a, S2b and S2c).


Model assumptions

# Table S1
m_ass(name = "Table S1 - full a", mo = ms, dat = d, fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - full b", mo = mx, dat = d, fixed = c("FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - CZ a", mo = cs, dat = d[Country == "Czechia"], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - CZ b", mo = cx, dat = d[Country == "Czechia"], fixed = c("FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - FI a", mo = fs, dat = d[Country == "Finland"], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - FI b", mo = fx, dat = d[Country == "Finland"], fixed = c("FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - HU a", mo = hs, dat = d[Country == "Hungary"], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - HU b", mo = hx, dat = d[Country == "Hungary"], fixed = c("FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - PL a", mo = ps, dat = d[Country == "Poland"], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - PL b", mo = px, dat = d[Country == "Poland"], fixed = c("FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - AU a", mo = as, dat = d[Country == "Australia"], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S1 - AU b", mo = ax, dat = d[Country == "Australia"], fixed = c("FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

# Table S2a
m_ass(name = "Table S2a - 1a", mo = m1a, dat = d, fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2a - 1b", mo = m1b, dat = d, fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2a - 1c", mo = m1c, dat = d, fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2a - 1d", mo = m1d, dat = d, fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2a - 1e", mo = m1d, dat = d, fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

dx4 <- dd[N_during > 4 & N_before > 4]
m_ass(name = "Table S2a - 2a", mo = m2a, dat = d[Species %in% dx4$Species], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2a - 2b", mo = m2b, dat = d[Species %in% dx4$Species], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2a - 2c", mo = m2c, dat = d[Species %in% dx4$Species], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

dx9 = dd[N_during > 9 & N_before > 9]
m_ass(name = "Table S2a - 3a", mo = m3a, dat = d[Species %in% dx9$Species], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2a - 3b", mo = m3b, dat = d[Species %in% dx9$Species], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2a - 3c", mo = m3c, dat = d[Species %in% dx9$Species], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Covid"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

# Table S2b
m_ass(name = "Table S2b - 1a", mo = m01a, dat = s, fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2b - 1b", mo = m01b, dat = s, fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2b - 1c", mo = m01c, dat = s, fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

m_ass(name = "Table S2b - 2a", mo = m02a, dat = s[Nsp > 4], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2b - 2b", mo = m02b, dat = s[Nsp > 4], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2b - 2c", mo = m02c, dat = s[Nsp > 4], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

m_ass(name = "Table S2b - 3a", mo = m03a, dat = s[Nsp > 9], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2b - 3b", mo = m03b, dat = s[Nsp > 9], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2b - 3c", mo = m03c, dat = s[Nsp > 9], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

# Table S2c
m_ass(name = "Table S2c - 1a", mo = mg01a, dat = ss, fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "parks_percent_change_from_baseline"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2c - 1b", mo = mg01b, dat = ss, fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "parks_percent_change_from_baseline"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2c - 1c", mo = mg01c, dat = ss, fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "parks_percent_change_from_baseline"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

m_ass(name = "Table S2c - 2a", mo = mg02a, dat = ss[Nsp > 4], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "parks_percent_change_from_baseline"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2c - 2b", mo = mg02b, dat = ss[Nsp > 4], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "parks_percent_change_from_baseline"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2c - 2c", mo = mg02c, dat = ss[Nsp > 4], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "parks_percent_change_from_baseline"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

m_ass(name = "Table S2c - 3a", mo = mg03a, dat = ss[Nsp > 9], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "parks_percent_change_from_baseline"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2c - 3b", mo = mg03b, dat = ss[Nsp > 9], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "parks_percent_change_from_baseline"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2c - 3c", mo = mg03c, dat = ss[Nsp > 9], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "parks_percent_change_from_baseline"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

# Table S2d
m_ass(name = "Table S2d - 1a", mo = mh01a, dat = dh, fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2d - 1b", mo = mh01b, dat = dh, fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2d - 1c", mo = mh01c, dat = dh, fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

m_ass(name = "Table S2d - 2a", mo = mh02a, dat = dh[Nsp > 4], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2d - 2b", mo = mh02b, dat = dh[Nsp > 4], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2d - 2c", mo = mh02c, dat = dh[Nsp > 4], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

m_ass(name = "Table S2d - 3a", mo = mh03a, dat = dh[Nsp > 9], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2d - 3b", mo = mh03b, dat = dh[Nsp > 9], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S2d - 3c", mo = mh03c, dat = dh[Nsp > 9], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

# Table S3a
m_ass(name = "Table S3a - FI", mo = fi, dat = ssf, fixed = c("Year", "StringencyIndex"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3a - PL", mo = pl, dat = ssp, fixed = c("Year", "StringencyIndex"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3a - CZ", mo = cz, dat = sscz, fixed = c("StringencyIndex"), trans = c(""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3a - HU", mo = hu, dat = ss_h, fixed = c("Year", "StringencyIndex"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3a - AU", mo = au, dat = ssa, fixed = c("Year", "StringencyIndex"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))

# Table S3b
m_ass(name = "Table S3b - FI", mo = shfi_, dat = shf, fixed = c("Year", "StringencyIndex"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3b - CZ", mo = shcz_, dat = shc, fixed = c("Year", "StringencyIndex"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3b - HU", mo = shhu_, dat = sh_h, fixed = c("Year", "StringencyIndex"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))

# Table S3c
m_ass(name = "Table S3c - FI", mo = shfi_ln_, dat = shf, fixed = c("Year", "StringencyIndex"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3c - CZ", mo = shcz_ln_, dat = shc, fixed = c("Year", "StringencyIndex"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3c - HU", mo = shhu_ln_, dat = sh_h, fixed = c("Year", "StringencyIndex"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))

# Table S3d
m_ass(name = "Table S3d - FI", mo = shfi_g, dat = sshf, fixed = c("Year", "parks_percent_change_from_baseline"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3d - CZ", mo = shcz_g, dat = sshc, fixed = c("Year", "parks_percent_change_from_baseline"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3d - HU", mo = shhu_g, dat = ssh_h, fixed = c("Year", "parks_percent_change_from_baseline"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))

# Table S3e
m_ass(name = "Table S3e - FI", mo = shfi_g_ln, dat = sshf, fixed = c("Year", "parks_percent_change_from_baseline"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3e - CZ", mo = shcz_g_ln, dat = sshc, fixed = c("Year", "parks_percent_change_from_baseline"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S3e - HU", mo = shhu_g_ln, dat = ssh_h, fixed = c("Year", "parks_percent_change_from_baseline"), trans = c("", ""), outdir = here::here("Outputs/modelAss/"))

# Table S4
m_ass(name = "Table S4 - full a", mo = mss, dat = s, fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - full b", mo = msx, dat = s, fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - FI a", mo = fss, dat = s[Country == "Finland"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - FI b", mo = fsx, dat = s[Country == "Finland"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - PL a", mo = pss, dat = s[Country == "Poland"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - PL b", mo = psx, dat = s[Country == "Poland"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("","log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - CZ a", mo = css, dat = s[Country == "Czechia"], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - CZ b", mo = csx, dat = s[Country == "Czechia"], fixed = c("FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - HU a", mo = hss, dat = s[Country == "Hungary"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - HU b", mo = hsx, dat = s[Country == "Hungary"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - AU a", mo = ass, dat = s[Country == "Australia"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S4 - AU b", mo = asx, dat = s[Country == "Australia"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

# Table SS
m_ass(name = "Table S5 - full a", mo = mgs, dat = ss, fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - full b", mo = mgx, dat = ss, fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - FI a", mo = fgs, dat = ss[Country == "Finland"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - FI b", mo = fgx, dat = ss[Country == "Finland"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - PL a", mo = pgs, dat = ss[Country == "Poland"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - PL b", mo = pgx, dat = ss[Country == "Poland"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - CZ a", mo = cgs, dat = ss[Country == "Czechia"], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - CZ b", mo = cgx, dat = ss[Country == "Czechia"], fixed = c("FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - HU a", mo = hgs, dat = ss[Country == "Hungary"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - HU b", mo = hgx, dat = ss[Country == "Hungary"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - AU a", mo = ags, dat = ss[Country == "Australia"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S5 - AU b", mo = agx, dat = ss[Country == "Australia"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "StringencyIndex"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

# Table S6
m_ass(name = "Table S6 - full a", mo = mhs, dat = dh, fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S6 - full b", mo = mhx, dat = dh, fixed = c("FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S6 - CZ a", mo = chs, dat = dh[Country == "Czechia"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S6 - CZ b", mo = chx, dat = dh[Country == "Czechia"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S6 - FI a", mo = fhs, dat = dh[Country == "Finland"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S6 - FI b", mo = fhx, dat = dh[Country == "Finland"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S6 - HU a", mo = hhs, dat = dh[Country == "Hungary"], fixed = c("Year", "SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("", "log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S6 - HU b", mo = hhx, dat = dh[Country == "Hungary"], fixed = c("Year", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S6 - PL a", mo = phs, dat = dh[Country == "Poland"], fixed = c("SD", "FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))
m_ass(name = "Table S6 - PL b", mo = phx, dat = dh[Country == "Poland"], fixed = c("FlockSize", "BodyMass", "rad", "rad", "Temp", "Human"), trans = c("log", "log", "sin", "cos", "", ""), outdir = here::here("Outputs/modelAss/"))

Titles indicate specific models from specific Tables and highlight the model formula in lmer syntax

for Table S1 | Escape distance in relations to Period, given country

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - full a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - full b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - FI a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - FI b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - PL a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - PL b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - CZ a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - CZ b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - HU a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - HU b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - AU a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S1 - AU b.png"))


for Table S2a | Alternative models on escape distance given Period

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 1a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 1b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 1c.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 1d.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 1e.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 2a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 2b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 2c.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 3a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 3b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2a - 3c.png"))


for Table S2b | Alternative models on escape distance given Stringency index

knitr::include_graphics(here::here("Outputs/modelAss/Table S2b - 1a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2b - 1b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2b - 1c.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2b - 2a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2b - 2b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2b - 2c.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2b - 3a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2b - 3b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2b - 3c.png"))


for Table S2c | Alternative models on escape distance given Google Mobility

knitr::include_graphics(here::here("Outputs/modelAss/Table S2c - 1a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2c - 1b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2c - 1c.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2c - 2a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2c - 2b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2c - 2c.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2c - 3a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2c - 3b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2c - 3c.png"))


for Table S2d | Alternative models on escape distance given # of humans

knitr::include_graphics(here::here("Outputs/modelAss/Table S2d - 1a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2d - 1b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2d - 1c.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2d - 2a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2d - 2b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2d - 2c.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2d - 3a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2d - 3b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S2d - 3c.png"))


for Table S3a | Google Mobility in relation to Stringency index

knitr::include_graphics(here::here("Outputs/modelAss/Table S3a - FI.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3a - PL.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3a - CZ.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3a - HU.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3a - AU.png"))


for Table S3b | Number of humans in relation to Stringency index

knitr::include_graphics(here::here("Outputs/modelAss/Table S3b - FI.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3b - CZ.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3b - HU.png"))


for Table S3c | Number of humans (ln-transformed) in relation to Stringency index

knitr::include_graphics(here::here("Outputs/modelAss/Table S3c - FI.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3c - CZ.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3c - HU.png"))


for Table S3d | Number of humans in relation to Google Mobility

knitr::include_graphics(here::here("Outputs/modelAss/Table S3d - FI.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3d - CZ.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3d - HU.png"))


for Table S3e | Number of humans (ln-transformed) in relation to Google Mobility

knitr::include_graphics(here::here("Outputs/modelAss/Table S3e - FI.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3e - CZ.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S3e - HU.png"))


for Table S4 | Escape distance in relation to Stringency index

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - full a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - full b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - FI a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - FI b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - PL a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - PL b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - CZ a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - CZ b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - HU a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - HU b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - AU a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S4 - AU b.png"))


for Table S5 | Escape distance in relations to Google Mobility

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - full a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - full b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - FI a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - FI b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - PL a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - PL b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - CZ a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - CZ b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - HU a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - HU b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - AU a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S5 - AU b.png"))


for Table S6 | Escape distance in relation to # of humans

knitr::include_graphics(here::here("Outputs/modelAss/Table S6 - full a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S6 - full b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S6 - FI a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S6 - FI b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S6 - PL a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S6 - PL b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S6 - CZ a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S6 - CZ b.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S6 - HU a.png"))

knitr::include_graphics(here::here("Outputs/modelAss/Table S6 - HU b.png"))


References

  • Bulla, M., Blumstein, D.T., Benedetti, Y., Floigl, K., Jokimäki, J., Kaisanlahti-Jokimäki, M.-L., Markó, G., Morelli, F., Siretckaia, A., Szakony, S., Weston, M.A., Zeid, F.A., Tryjanowski, P., Albrecht, T. & Mikula, P. (2022). Supporting information for ‘Urban birds’ flight responses were unaffected by the COVID-19 shutdowns’. Open Science Framework https://doi.org/10.17605/OSF.IO/WUZH7.
  • Bürkner PC. (2018). Advanced Bayesian multilevel modeling with the R package brms. R Journal 10:395–411. https://doi.org/10.32614/RJ-2018-017
  • Bürkner PC. (2017). brms: An R package for Bayesian multilevel models using Stan. J Stat Softw 80:1–28. https://doi.org/10.18637/jss.v080.i01
  • Gelman, A., Su, Y.-S., Yajima, M., Hill, J., Pittau, M., Kerman, J., Zheng, T., & Vincent, D. (2016). Data Analysis using Regression and Multilevel/Hierarchical Models. In CRAN Repository (1.8-6.; pp. 1–53).
  • Hale T., Angrist N., Goldszmidt R., Kira B., Petherick A., Phillips T., Webster S., Cameron-Blake E., Hallas L., Majumdar S., Tatlow H. (2021). A global panel database of pandemic policies (Oxford COVID-19 Government Response Tracker). Nature Human Behaviour 2021 5:4 5:529–538. https://doi.org/10.1038/s41562-021-01079-8.
  • Peterson, B. G., & Carl, P. (2020). PerformanceAnalytics: Econometric Tools for Performance and Risk Analysis. R package version 2.0.4. https://CRAN.R-project.org/package=PerformanceAnalytics
  • Stan Development Team (2022). Stan Modeling Language Users Guide and Reference Manual, Version 2.28. https://mc-stan.org/users/documentation/
  • Wickham, H. (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag, New York.

Session info

  sessionInfo()
## R version 4.2.0 (2022-04-22)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Mojave 10.14.6
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] parallel  grid      stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] patchwork_1.1.1            plyr_1.8.7                 stringr_1.5.0              phytools_1.3-1             maps_3.4.1                
##  [6] car_3.0-13                 magrittr_2.0.3             phylobase_0.8.10           phangorn_2.10.0            MCMCglmm_2.33             
## [11] geiger_2.0.9               dplyr_1.0.10               coda_0.19-4                brms_2.17.0                Rcpp_1.0.9                
## [16] viridis_0.6.2              viridisLite_0.4.1          scales_1.2.1               rphylopic_0.3.0            rmeta_3.0                 
## [21] RColorBrewer_1.1-3         png_0.1-7                  performance_0.9.0          optimx_2022-4.30           multcomp_1.4-19           
## [26] TH.data_1.1-1              survival_3.3-1             mvtnorm_1.1-3              kableExtra_1.3.4           here_1.0.1                
## [31] gtable_0.3.1               ggtext_0.1.2               ggsci_2.9                  ggpubr_0.4.0               ggimage_0.3.1             
## [36] ggplot2_3.3.6              foreach_1.5.2              effects_4.2-1              carData_3.0-5              arm_1.12-2                
## [41] lme4_1.1-29                Matrix_1.4-1               MASS_7.3-57                PerformanceAnalytics_2.0.4 xts_0.12.1                
## [46] zoo_1.8-10                 rmarkdown_2.18             ape_5.6-2                  data.table_1.14.6         
## 
## loaded via a namespace (and not attached):
##   [1] utf8_1.2.2              ggstance_0.3.5          tidyselect_1.2.0        htmlwidgets_1.5.4       combinat_0.0-8          RNeXML_2.4.7           
##   [7] munsell_0.5.0           ragg_1.2.2              codetools_0.2-18        DT_0.23                 miniUI_0.1.1.1          withr_2.5.0            
##  [13] Brobdingnag_1.2-7       colorspace_2.0-3        uuid_1.1-0              highr_0.9               knitr_1.41              rstudioapi_0.14        
##  [19] stats4_4.2.0            ggsignif_0.6.3          bayesplot_1.9.0         labeling_0.4.2          emmeans_1.7.4-1         rstan_2.21.5           
##  [25] optimParallel_1.0-2     mnormt_2.1.1            farver_2.1.1            bridgesampling_1.1-2    rprojroot_2.0.3         vctrs_0.5.1            
##  [31] generics_0.1.3          clusterGeneration_1.3.7 xfun_0.35               R6_2.5.1                markdown_1.1            cachem_1.0.6           
##  [37] gridGraphics_0.5-1      assertthat_0.2.1        promises_1.2.0.1        nnet_7.3-17             processx_3.8.0          sandwich_3.0-1         
##  [43] rlang_1.0.6             systemfonts_1.0.4       scatterplot3d_0.3-42    splines_4.2.0           lazyeval_0.2.2          rstatix_0.7.0          
##  [49] broom_0.8.0             checkmate_2.1.0         inline_0.3.19           yaml_2.3.6              reshape2_1.4.4          abind_1.4-5            
##  [55] threejs_0.3.3           crosstalk_1.2.0         backports_1.4.1         httpuv_1.6.5            gridtext_0.1.4          tensorA_0.36.2         
##  [61] tools_4.2.0             ggplotify_0.1.0         gridBase_0.4-7          cubature_2.0.4.4        ellipsis_0.3.2          jquerylib_0.1.4        
##  [67] posterior_1.2.2         ggridges_0.5.3          progress_1.2.2          base64enc_0.1-3         purrr_0.3.4             ps_1.7.2               
##  [73] prettyunits_1.1.1       cowplot_1.1.1           deSolve_1.32            survey_4.1-1            crul_1.2.0              magick_2.7.3           
##  [79] colourpicker_1.1.1      matrixStats_0.62.0      hms_1.1.2               shinyjs_2.1.0           mime_0.12               evaluate_0.18          
##  [85] xtable_1.8-4            XML_3.99-0.9            shinystan_2.6.0         gridExtra_2.3           rstantools_2.2.0        compiler_4.2.0         
##  [91] tibble_3.1.8            crayon_1.5.1            minqa_1.2.4             StanHeaders_2.21.0-7    htmltools_0.5.4         mgcv_1.8-40            
##  [97] corpcor_1.6.10          ggfun_0.0.6             later_1.3.0             tidyr_1.2.0             expm_0.999-6            RcppParallel_5.1.5     
## [103] DBI_1.1.3               subplex_1.8             boot_1.3-28             ade4_1.7-19             cli_3.4.1               mitools_2.4            
## [109] quadprog_1.5-8          insight_0.18.8          igraph_1.3.5            pkgconfig_2.0.3         rncl_0.8.6              numDeriv_2016.8-1.1    
## [115] xml2_1.3.3              dygraphs_1.1.1.6        svglite_2.1.0           bslib_0.4.1             webshot_0.5.4           estimability_1.3       
## [121] rvest_1.0.3             yulab.utils_0.0.4       distributional_0.3.0    callr_3.7.3             digest_0.6.30           httpcode_0.3.0         
## [127] fastmatch_1.1-3         curl_4.3.3              shiny_1.7.1             gtools_3.9.2            nloptr_2.0.3            lifecycle_1.0.3        
## [133] nlme_3.1-157            jsonlite_1.8.4          fansi_1.0.3             pillar_1.8.1            lattice_0.20-45         loo_2.5.1              
## [139] plotrix_3.8-2           fastmap_1.1.0           httr_1.4.4              pkgbuild_1.3.1          glue_1.6.2              shinythemes_1.2.0      
## [145] iterators_1.0.14        stringi_1.7.8           sass_0.4.4              textshaping_0.3.6
# END